Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating letters entry

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0

How do I validate a name field where it shows a message box after someone enters a number in the name field. After I enter a number in the name field I want to validate it after leaving the field with a message box saying "Invalid entry-do not enter a number".

Also does this go into the 'on exit' event??

 
Why not cut the users off at the knees?????

In the table, set the input mask to only allow alpha characters....

The below is from the Access97 Help files on Input Mask Options...

0 Digit (0 to 9, entry required, plus [+] and minus [–] signs not allowed).
9 Digit or space (entry not required, plus and minus signs not allowed).
# Digit or space (entry not required; spaces are displayed as blanks while in Edit mode, but blanks are removed when data is saved; plus and minus signs allowed).
L Letter (A to Z, entry required).
? Letter (A to Z, entry optional).
A Letter or digit (entry required).
a Letter or digit (entry optional).
& Any character or a space (entry required).
C Any character or a space (entry optional).
. , : ; - / Decimal placeholder and thousand, date, and time separators. (The actual character used depends on the settings in the Regional Settings Properties dialog box in Windows Control Panel).
< Causes all characters to be converted to lowercase.
> Causes all characters to be converted to uppercase.
! Causes the input mask to display from right to left, rather than from left to right. Characters typed into the mask always fill it from left to right. You can include the exclamation point anywhere in the input mask.
\ Causes the character that follows to be displayed as the literal character (for example, \A is displayed as just A). It's not important that someone else can do in one step what it took you ten to do...the important thing is that you found a solution. [spin]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
 
I find that a neat way to do this is to stop the keyboard from doing anything when the user presses a number key.

The first method just does nothing when the user presses a number key:

On the 'On Key Press' event of the text box that the user is trying to type into attatch the following code....


If KeyAscii >= 48 And KeyAscii <= 57 Then
KeyAscii = 0
End If



If you want to display a message box replace the above code with following.......


If KeyAscii >= 48 And KeyAscii <= 57 Then
KeyAscii = 0
MsgBox &quot;Invalid entry-do not enter a number&quot;
End If

Hope that helps

Bow
 
Cool idea bevans1....had not thought of that one myself! Thanks.

(open his reference database and adds this one to it) It's not important that someone else can do in one step what it took you ten to do...the important thing is that you found a solution. [spin]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
 
I find this helpful:

Add the following code to the 'On Key Press' event of the text box that the user is entering data into.
It disables the number keys for that text box, so you do not really have to put the message box in if you don't want to........

If KeyAscii >= 48 And KeyAscii <= 57 Then
KeyAscii = 0
MsgBox &quot;Invalid entry-do not enter a number&quot;
End If

Bow
 
Thank you to all.

What are the numbers between 48 and 57?
Are these some sort of Ascii set numbers?
And why is KeyAscii set to zero if the keyAscii is between 48 and 57??

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top