Hi,
I have the following code which sits behind a userform in Excel VBA. What I want is that when the user clicks or tabs out of a textbox, the TestNumeric procedure is called, which checks to see if the values are numeric. If not, a messagebox is produced and the cursor focus is sent back to the original textbox.
My code works fine, except that the cursor focus is not going back to the original textbox, but staying with whatever object has been clicked.
Can anybody help?
Here is my code:-
I have the following code which sits behind a userform in Excel VBA. What I want is that when the user clicks or tabs out of a textbox, the TestNumeric procedure is called, which checks to see if the values are numeric. If not, a messagebox is produced and the cursor focus is sent back to the original textbox.
My code works fine, except that the cursor focus is not going back to the original textbox, but staying with whatever object has been clicked.
Can anybody help?
Here is my code:-
Code:
Dim MyObject As Object
Private Sub NumberOfFloors_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Set MyObject = NumberOfFloors
Call TestNumeric(MyObject)
End Sub
Private Sub TestNumeric(Object)
If Object.Value <> "" And Not IsNumeric(Object.Value)Then
MsgBox ("Enter numeric values only")
Object.SetFocus
End If
End Sub