Don't allow alpha numeric in a field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to in a field rather than causing an error message because in
a currency field someone typed in a alpha characterto just let the field
ignore the alpha characters and only put in numeric numbers that are typed in.

Thanks in advance
 
Do you mean text box on a form, or field in a table?

In either case, see Access Help for Input Mask
 
Is there a way to in a field rather than causing an error message because in
a currency field someone typed in a alpha characterto just let the field
ignore the alpha characters and only put in numeric numbers that are typed in.

Thanks in advance

An Input Mask (as Klatuu suggests) is certainly the simplest solution
to implement, and will accomplish the goal - the user will get an
error message box, though, which might interrupt their thought
process. (It will fairly quickly train them not to type letters in the
field though!)

Alternatively, you can use VBA code in the control's KeyDown event to
trap each keystroke, check to see if it's numeric, and discard it if
not. You need to set the Form's KeyPreview property to True, and use
code like

Private Sub txtMyTextbox_KeyDown(KeyCode As Integer, Shift as Integer)
If KeyCode < Asc("0") Or KeyCode > Asc("9") Then ' trap all nonnumeric
KeyCode = 0 ' Untype the character - user gets nothing
Beep ' let the user know something odd happened
End If
End Sub

John W. Vinson[MVP]
 
Hey John,

I do want the user to be able to utilize the Tab button to move to different
fields. Is it possible to allow that button to be utilized?

Thanks in advance,
John
 
Hey John,

I do want the user to be able to utilize the Tab button to move to different
fields. Is it possible to allow that button to be utilized?

Sure, just check for vbTab in the code and allow it (just like you
allow numeric digits). Check for vbEnter as well! Sorry about the
oversight.

John W. Vinson[MVP]
 
Back
Top