Hello Guessed and GMaxey,
I have implemented both of your ideas into my Validation process but am having problems with the focus being returned to my first texbox (txt1) if validation fails. Currently, the focus moves to my second textbox (txt2). I am using the TAB key to advance the cursor from textbox to textbox. Maybe it is the end of the week and I am missing something easy.
Here is my code for the Validate procedure I have created:
Code:
Sub Validate(ControlNumber As Integer)
Select Case ControlNumber
Case 1
'number only
If Not IsNumeric(txt1.Text) Then
MsgBox ("Must be a Number")
txt1.SetFocus
End If
'Case 2,3,4,5,6,7,8 to follow
End Select
End Sub
Here is the code for the txt1 AfterUpdate event:
Code:
Private Sub txt1_AfterUpdate()
txt1.BackColor = vbWhite
Validate (1)
End Sub
If I run the form and type in a letter, the code detects the error and displays the message box as planned. However, when I click OK, the focus is not returned to the txt1 control. It moves to the txt2 control meaning the user could ignore the error.
How do I get the focus to return to txt1 and keep it there as many times as necessary until user puts in only numbers? Maybe I am using the incorrect event or missing something easy? Thanks