Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlight controls and bold and highlight its label

Status
Not open for further replies.

nikademous

Technical User
Sep 9, 2018
41
0
0
US
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!

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
 
To highlight (change the Format) of a control on a continuous form you will need to use Conditional Formatting based on the primary key/unique value in the record. To highlight the label at the top of the column, you can use some code but must have some type of naming convention. For instance the name of the label could be "lbl" + the Control Source. Then your code might include something like:

Code:
Me("lbl" & clt.ControlSource).BorderColor = RGB(255,0,0)

You would also need to add a line to turn off the red.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top