S
sfrvn
I often have forms with (too) many textboxes. To assist users, I
prefer to change the back color of the textbox when it has the focus.
It is easy for the User to locate where they are on the form. However,
coding each textbox's GotFocus and LostFocus event is very tedious if
you use the Me![tbxName].BackColor = 12713983 syntax for these
events. The problem stems from having to use the specific textbox name
for each event for each control. Cut-and-Paste can only do so much.
Even after searching the newsgroups, I failed to find an easy method to
accomplish this goal.
Using info I found in the newsgroups, I constructed the following code
together. The value of the code rests in its 'universal' nature. Once
you create the GotFocus and LostFocus events for the textboxes, you
simply copy/paste the appropriate code into each 'sub'. You do not
need to specify the name of the control. This makes the process of
customizing 50 textboxes x 2 events much easier.
Sample code follows:
Private Sub tbxName_GotFocus()
'Copy the following 3 lines into all GotFocus events
Dim CurrCtl As String
CurrCtl = Screen.ActiveControl.Name
Me(CurrCtl).BackColor = 12713983
End Sub
Private Sub tbxName_LostFocus()
'Copy the following 3 lines into all LostFocus events
Dim CurrCtl As String
CurrCtl = Screen.ActiveControl.Name
Me(CurrCtl).BackColor = 16777215
End Sub
Obviously, you can adapt the code to change textbox properties as you
see fit.
Hope you find this useful.
Gary B
prefer to change the back color of the textbox when it has the focus.
It is easy for the User to locate where they are on the form. However,
coding each textbox's GotFocus and LostFocus event is very tedious if
you use the Me![tbxName].BackColor = 12713983 syntax for these
events. The problem stems from having to use the specific textbox name
for each event for each control. Cut-and-Paste can only do so much.
Even after searching the newsgroups, I failed to find an easy method to
accomplish this goal.
Using info I found in the newsgroups, I constructed the following code
together. The value of the code rests in its 'universal' nature. Once
you create the GotFocus and LostFocus events for the textboxes, you
simply copy/paste the appropriate code into each 'sub'. You do not
need to specify the name of the control. This makes the process of
customizing 50 textboxes x 2 events much easier.
Sample code follows:
Private Sub tbxName_GotFocus()
'Copy the following 3 lines into all GotFocus events
Dim CurrCtl As String
CurrCtl = Screen.ActiveControl.Name
Me(CurrCtl).BackColor = 12713983
End Sub
Private Sub tbxName_LostFocus()
'Copy the following 3 lines into all LostFocus events
Dim CurrCtl As String
CurrCtl = Screen.ActiveControl.Name
Me(CurrCtl).BackColor = 16777215
End Sub
Obviously, you can adapt the code to change textbox properties as you
see fit.
Hope you find this useful.
Gary B