Friday, June 13, 2014

Access Field Highlighting

More code


This technique can also be applied to controls like option groups.

Instead of using OnGotFocus and OnLostFocus events you must use the OnEnter and OnExit events.

In addition, the control group's BackStyle property must be set to Normal to take advantage of the Windows color scheme:

Function Highlight(Stat As String) As Integer
Dim ctrl As Control
On Error Resume Next
Set ctrl = Screen.ActiveControl
If Stat = "GotFocus" Then
ctrl.BackColor = vbHighlight
ctrl.ForeColor = vbHighlightText
ElseIf Stat = "LostFocus" Then
ctrl.BackColor = vbWindowBackground
ctrl.ForeColor = vbWindowText
End If
End Function

Take advantage of global constants. Just add the following two statements to a module:

Global Const Orange = 39423
Global Const LightBlue = 16776960

Then, set the OnGotFocus and OnLostFocus events for the controls in the following format:
Private Sub controlName_GotFocus()
controlname.BackColor = Orange
End Sub
Private Sub controlName_LostFocus()
controlname.BackColor = LightBlue
End Sub




See all Topics

No comments: