nikademous
Technical User
Hello, I found the code below to highlight the control that has focus and it works great but I also wanted it to:
[ol]
[li]Highlight or bold the controls label that has focus.[/li]
[li]Be able to use in a continuous form. Right now if I select a control in my detail section, it selects every control down the form.[/li]
[/ol]
What is needed in the below VBA for these two items to work? Thanks!
[ol]
[li]Highlight or bold the controls label that has focus.[/li]
[li]Be able to use in a continuous form. Right now if I select a control in my detail section, it selects every control down the form.[/li]
[/ol]
What is needed in the below VBA for these two items to work? Thanks!
Code:
'======================================================================================
'Each Control will need “HighlightOnFocus” in its Tag property. and called from forms
' OnLoad Event using SetFocusHandlers Me
'======================================================================================
Public Function SetFocusHandlers(ByRef frm As Form)
Dim ctl As Control
For Each ctl In frm
If ctl.Tag = "HighlightOnFocus" Then
ctl.OnGotFocus = "=HandleFocus([" & ctl.Name & "], True)"
ctl.OnLostFocus = "=HandleFocus([" & ctl.Name & "], False)"
End If
Next
End Function
Public Function HandleFocus(ByRef ctl As Control, ByVal blnFocus As Boolean)
If blnFocus = True Then
ctl.BorderColor = RGB(255, 0, 0)
ctl.BorderWidth = 2
Else
ctl.BorderColor = RGB(122, 138, 153)
ctl.BorderWidth = 1
End If
End Function