only numbers

  • Thread starter Thread starter Gary Hull
  • Start date Start date
G

Gary Hull

I have an unbound text field on a form I only want to enter Numbers in the
field how can I make it where the field only accepts numbers
 
Just set the Format property of the text box to something like General
Number. Then Access won't let you out of the box if you enter something
non-numeric.
 
Gary Hull said:
I have an unbound text field on a form I only want to enter Numbers in the
field how can I make it where the field only accepts numbers

In addition to Allen's suggestion, if you want to restrict users more
aggressively, you can disallow non-numeric keypresses altogether (as they
type). Paste this function into a standard module:

Public Function KeyNumeric(KeyAscii As Integer) As Integer
' Called from keypress event of an unbound textbox
' Restricts the keypresses to numeric chars only
'
' syntax to use: KeyNumeric KeyAscii

Select Case KeyAscii
Case 8, 9, 13, 27 'Allow B/space,tab,return & esc
KeyNumeric = KeyAscii
Exit Function
Case 48 To 57 'Allow numerics
KeyNumeric = KeyAscii
Case Else 'Disallow anything else
Beep
KeyAscii = 0
End Select
End Function

Then, in a keypress event procedure for your control, type:

KeyNumeric KeyAscii
 
Back
Top