I have several forms containing bound controls in which a phone number is to be entered. Because I want the saved text string to include spaces here and there (e.g. 07 1234 5678 for land lines, or 0412 345 678 for mobiles), I have a function which reformats the given text string. Since the control is bound to the requisite control source, the reformatted phone number is automatically stored in the record. The function is called from the AfterUpdate procedure of the control, and works well.
If, however, the user enters an invalid string (e.g. nonnumeric characters, or wrong number of digits), the functon outputs an error message asking the user to re-enter it, and returns the word "Invalid". To avoid the risk of the user missing the message and moving on, I then want to keep the focus on the same control. However the SetFocus command doesn't work (or perhaps it works but then is immediately overridden) and the focus moves to control with the the next tab stop. Is there any way I can fix this? (The control is, of course, enabled and unlocked).
If, however, the user enters an invalid string (e.g. nonnumeric characters, or wrong number of digits), the functon outputs an error message asking the user to re-enter it, and returns the word "Invalid". To avoid the risk of the user missing the message and moving on, I then want to keep the focus on the same control. However the SetFocus command doesn't work (or perhaps it works but then is immediately overridden) and the focus moves to control with the the next tab stop. Is there any way I can fix this? (The control is, of course, enabled and unlocked).
Code:
Private Sub txtHome_phone_AfterUpdate()
'
' Checks and standardises format of home phone numbers. It will accept them either with or without area codes.
'
Me!txtHome_phone = Nz(FixPhoneNum(Me!txtHome_phone))
If Me!txtHome_phone = "Invalid" Then
Me!txtHome_phone.SetFocus ' Unfortunately, this doesn't work and I don't know why :-(
End If
Exit Sub
End Sub
Comment