numbers only input mask, if checking for number

Mr.K

Registered User.
Local time
Today, 02:24
Joined
Jan 18, 2006
Messages
104
I have a control called GoToId which afterupdate moves the user to a specified record where ID=GotoID. I want the control to only take numbers as input. I used input mask: 999999;;" " but with it the user can still press a letter on a keyboard and even though the letter doesn't get typed in, I think an empty string gets passed as value.
If I can't do it with masks, what's the simplest if statement in vba that will check if the value is a number and positive? (IF the value is Null, "", or anything else I want the if expression to be false)
I know how to do it with several if statements checking if is null, or if "", but there must be a clean way of asking it in a single expression.
 
Have yopu tried the IsNumeric finction? This may help trap the alpha characters.

Private Sub Text1_Exit(Cancel As Integer)

If IsNumeric(Text1.Value) Then
MsgBox "ok"
Else
MsgBox "Alpha"
End If

End Sub
 
Search around for code samples using the KeyPress and or KeyDown events for I have posted code [somewhere in this forum] on how to not allow a user to press specific keys when I want to restrict what they can type in a specific field. Much better than messing with an input mask.
 
Thanks. IsNumeric does it; I didn't know about this function :o
 

Users who are viewing this thread

Back
Top Bottom