On Got Focus

J

JennKriv

I have a timesheet form in which I have the date name and other headings such
as layout and sawing on it. It is a continuous form. What I am looking to do
is that as I am working in the text box I want the label above to highlight
so I know that I am in the correct field.

I found this code but I don't know how to fix it,
My fields i want to change are LBLLayout, which I want to bold when the
cursor is focused on text box Layout.
Any Ideas, is this even a code that would work for me?


Private lblMagic As Label
Private Const conHighlightOff = 500
Private Const conHighlightOn = 600
Private Const conCmdForeColorNotSelected As Long = &H606060
Private Const conCmdForeColorSelected As Long = 12941568

Private Sub MagicLabelOn(lbl As Label)
Dim bDoNothing As Boolean
If Not lblMagic Is Nothing Then
If lbl.Name = lblMagic.Name Then
bDoNothing = True
Else
Call MagicLabelOff
End If
End If
If Not bDoNothing Then
lbl.FontWeight = conHighlightOn
lbl.Parent.ForeColor = conCmdForeColorSelected
Set lblMagic = lbl
End If
End Sub
Private Sub MagicLabelOff()
If Not lblMagic Is Nothing Then
lblMagic.FontWeight = conHighlightOff
lblMagic.Parent.ForeColor = conCmdForeColorNotSelected
Set lblMagic = Nothing
End If
End Sub
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Call MagicLabelOff
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set lblMagic = Nothing
End Sub

'Example of what goes in the GotFocus and MouseMove of each command button:
Private Sub cmdReport_GotFocus()
Call MagicLabelOn(Me.lblcmdReport)
End Sub
Private Sub cmdReport_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Call MagicLabelOn(Me.lblcmdReport)
End Sub
 
E

Evi

To highlight any label whose control is highlighted, name your labels with
the same name as their text box but with the prefix lbl.So if the text box
is called MyField, your label will be called lblMyField. Ensure that each
label's Back Style is set to Normal

At the top of the code page of your form, just under where it says stuff
like Option Explicit, put
Const MyColorOn = 255
'red - adjust as wished
Const MyColorOff = -2147483633
'grey - adjust as wished

Then you can use the code in the OnGotFocus Event of each text box
Dim MyLabel As String
MyLabel = "lbl" & Me.ActiveControl.Name
Me (MyLabel).BackColor =MyColorOn

In the LostFocus Event of the control you can thus have

Dim MyLabel As String

MyLabel = "lbl" & Me.ActiveControl.Name
Me (MyLabel).BackColor =MyColorOff

Evi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top