I need to have a sub deal with changes made to text strings in text box controls, in this case a sub named "TestForChange". There will be quite a number of "GotFocus"/"LostFocus" pairs associated with the current form. Corresponding to the text boxes are boolean fields where a flag is set to denote that a field has changed. The boolean controls have consistent naming with their text box counterparts. E.g., the tbFirstName counterpart is "ChgFirstName" so the "TestForChange" sub needs to parse the control name in order to produce the counterpart name and hense the need to pass the control name. The code below IS WRONG in that it passes the text as opposed to the control that contains it.
What do I need to do to fix this?
Thanks,
Bill
Code:
Private Sub tbFirstName_GotFocus()
strAtFocus = Me.tbFirstName.Text
End Sub
Private Sub tbFirstName_LostFocus()
Call TestForChange(tbFirstName)
End Sub
Private Sub TestForChange(CtrlName As Control)
If Me(CtrlName).Text <> strAtFocus Then _
MsgBox "Strings not equal"
End Sub