Number validation

  • Thread starter Thread starter vbcraft
  • Start date Start date
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.
 
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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top