This almost does it. I am trying to change the bacground color of a text box that gets focus and reset it back to white when focus leaves it.
The problem I am having with this is that it will set the background color but the same code (with the correct value to for white) does not unset it on the LostFocus event.
It does work if I hard hard both events (text1.BackColor = &HFFFF& etc.)
My goal is offcourse to have one command for changing the BackColor not having to know every controls name.
You cannot use Me.ActiveControl.BackColor in the lost_focus event because the other textbox has the focus. It is only good for the object that has the focus.
Private Sub Text1_GotFocus()
Me.ActiveControl.BackColor = &HFFFFF
End Sub
Private Sub Text1_LostFocus()
Me.Text1.BackColor = &HFFFFFF
Debug.Print Me.ActiveControl
End Sub
Private Sub Text2_GotFocus()
Me.ActiveControl.BackColor = &HFFFFF
End Sub
Private Sub Text2_LostFocus()
Me.Text2.BackColor = &HFFFFFF
Debug.Print Me.ActiveControl
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.