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:
- Go to Form Design View
- Select all the controls you want to obscure ([Ctrl]/[Shift] + Click)
- Set the On Enter property to:
=ObscureInfo(False, Form.ActiveControl)
- Set the On Exit property to:
=ObscureInfo(True, Form.ActiveControl)
- Select the form itself
- Set the On Current property to:
=ObscureInfo(True, [tbBirthDate], [tbSSN])
- 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:
When we tab into the next sensitive field, the previous field blacks out and the new field's contents become visible:
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: