Not allow alpha's in a text field

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

Guest

Hi,
I have a txt field where they user can enter a number. I have the format
property set to General Number. So it they enter a letter, it tells them it
is an invalid value. But I don't want them to get that far. As soon as they
hit the alpha on the keyboard, I want to either not let them enter it at all,
or stop them right there.
Any ideas on how to do that?
Thanks
 
Sure, just use the "keydown" event of the contorl.

If (KeyCode < Asc("0")) Or (KeyCode > Asc("9")) Then
Beep
KeyCode = 0
End If
 
Hi, Steve.

Another way is to use an input mask on the text box, but it's not quite as
flexible as using code, since the number of possible digits needs to be known
beforehand in order to place a mask on each allowable ordinal position within
the number.

Use 0 for any required digit (+ and - not allowed)
Use 9 for any optional digit or space (+ and - not allowed)
Use # for any optional digit or space (+ and - allowed)

For example, if you needed a positive number up to three digits:

990

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Back
Top