ObscureInfo(): Hide Sensitive Information in Access Form Controls

To prevent over-the-shoulder attacks–or accidental disclosure during presentations or screenshots–it's good practice to hide the contents of sensitive information in your Access forms.

The ObscureInfo() function does just that.  When the control does not have the focus, the function sets the back color to match the fore color (i.e., the text color).  When the control gets the focus, the back color is set to white.  

The code is easy to apply to multiple controls and is compatible with lightweight forms (i.e., you can call the function directly from the Property Sheet events without needing to use the form code behind module).

The Code

' ----------------------------------------------------------------
' Procedure : ObscureInfo
' Date      : 9/21/2009
' Author    : Mike Wolfe
' Source    : https://nolongerset.com/obscureinfo/
' Purpose   : Use to hide data in sensitive fields (e.g., BirthDate, PhoneNum, SSN)
' Usage     : Ctl OnEnter  property: =ObscureInfo(False, Form.ActiveControl)
'             Ctl OnExit   property: =ObscureInfo(True, Form.ActiveControl)
'             Form Current property: =ObscureInfo(True, [BirthDate], [HomePhone], [SSN])
'             Form Load    property: =ObscureInfo(True, [BirthDate], [HomePhone], [SSN])
' ----------------------------------------------------------------
Function ObscureInfo(HideIt As Boolean, ParamArray Ctls() As Variant)
    Dim Ctl As Variant
    For Each Ctl In Ctls
        If HideIt Then
            If IsNull(Ctl.Value) Then
                Ctl.BackColor = vbWhite
            Else
                Ctl.BackColor = Ctl.ForeColor
            End If
        Else
            Ctl.BackColor = vbWhite
        End If
    Next Ctl
End Function

Usage: Step-by-Step

The easiest way to apply the changes in form design view is by using the Property Sheet events.  

Here's the step-by-step process:

  1. Go to Form Design View
  2. Select all the controls you want to obscure ([Ctrl]/[Shift] + Click)
  3. Set the On Enter property to: =ObscureInfo(False, Form.ActiveControl)
  4. Set the On Exit property to: =ObscureInfo(True, Form.ActiveControl)
  5. Select the form itself
  6. Set the On Current property to: =ObscureInfo(True, [tbBirthDate], [tbSSN])
  7. Set the On Load property to: =ObscureInfo(True, [tbBirthDate], [tbSSN])

For step 6, you list the control name (not the field name) of every control you want to be initially obscured when the form opens.

In Action

The controls only get obscured if they contain data.  So, for a new record, all the controls have white backgrounds.

When we switch to a populated record, the sensitive information is blacked out:

When we tab into one of the sensitive fields, the background turns white and we can see its contents:

The "Soc Sec Num" text box is active. If you look closely, you can see the cursor before the "123-45-6789" text.

When we tab into the next sensitive field, the previous field blacks out and the new field's contents become visible:

Tabbing from "Soc Sec Num" to "Home Phone" obscures the Soc Sec Num field, selects the text in the Home Phone field, and sets the back color to white so we can see its contents.

Sample Database

There's not much to the code, but if you would like to see it in action, you can download the database I used for the above screenshots:

ObscureInfoSample.zip