Hi,
I need to take a user input into a form.textbox and verify it is an integer before the program continues. it's critical the user inserts only an integer. I'm at a loss as to how to accomplish this though. I'll insert the code I've tried below.
The problem with this code is that if they enter anything besides an integer it returns a data type mismatch error, so it doesn't accomplish it's purpose. Ideas?
I need to take a user input into a form.textbox and verify it is an integer before the program continues. it's critical the user inserts only an integer. I'm at a loss as to how to accomplish this though. I'll insert the code I've tried below.
Code:
Private Sub TextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox.Text <> "" Then
If TextBox.Text > 0 And TextBox.Text < 100000000 Then
Exit Sub
Else
Response = MsgBox("Please insert a valid number.", vbOKOnly, "Error")
End If
End If
End Sub
The problem with this code is that if they enter anything besides an integer it returns a data type mismatch error, so it doesn't accomplish it's purpose. Ideas?