Number validation

P

Peter Hibbs

Yes, in the KeyPress event enter the following code like so :-

Private Sub YourFieldName_KeyPress(KeyAscii As Integer)

If Chr(KeyAscii) Like "[!0-9.]" And KeyAscii <> vbKeyBack Then
KeyAscii = 0

End Sub

where YourFieldName is the name of your text box control. Note that
the code should all be on one line and if you do not need decimal
points then omit the . character. If you need to be able to enter
negative values, add the - characters to the end of the string, i.e.

Like "[!0-9.-]

HTH

Peter Hibbs.
 
J

John Spencer

If you want to use the validation rule to do this you can use the
following as the validation rule.

Not Like "*[!0-9]*"

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================


Peter said:
Yes, in the KeyPress event enter the following code like so :-

Private Sub YourFieldName_KeyPress(KeyAscii As Integer)

If Chr(KeyAscii) Like "[!0-9.]" And KeyAscii <> vbKeyBack Then
KeyAscii = 0

End Sub

where YourFieldName is the name of your text box control. Note that
the code should all be on one line and if you do not need decimal
points then omit the . character. If you need to be able to enter
negative values, add the - characters to the end of the string, i.e.

Like "[!0-9.-]

HTH

Peter Hibbs.

Is there a way to accept only numbers in a form field.
Validation...
 
Top