Validation rules

C

Chris Lee

Please help
how can i only allow user to type leters (like
christopher) only!! not characters (like chris%&her)

many thanks chris:)
 
T

tina

if you're only allowing a limited number of characters to be entered, for
instance 10, the easiest way i can think of is to add an Input Mask. see the
Input Mask Property topic in Access Help for details.

if you're not limiting the number of characters to be entered, and are doing
the data entry from a form, you can write code that will check the field
data character by character. i've seen examples of such code in recent posts
here in the newsgroups, but not having used the code myself, i don't feel
competent to advise you specifically, sorry.

hth
 
J

John Nurick

Hi Chris,

In Table Design, set a validation rule on the field, like this:

Is Null Or Not Like "*[!A-Za-z]*"

Is Null allows the field to be left empty; remove it if the field must
be filled.

Like "*[!A-Za-z]*" requires at least one character that is not a letter,
and the Not reverses that, thus forbidding any character that is not a
letter.

Users will be able to type anything but the validation rule will be
applied when they move away from the field (including trying to update
the record). If you want also to make it impossible to type incorrect
characters, put something like this in the KeyPress event handler of the
textbox that is displaying the field:

Select Case KeyAscii
Case 8, 9, 13 'Backspace, tab, enter: process these
'Do nothing
Case 65 to 90, 97 to 122 'A-Z, a-z
'Do nothing
Case Else
'supress the keystroke
KeyAscii = 0
End Select
 
T

tina

cool, both - thanks John! :)


John Nurick said:
Hi Chris,

In Table Design, set a validation rule on the field, like this:

Is Null Or Not Like "*[!A-Za-z]*"

Is Null allows the field to be left empty; remove it if the field must
be filled.

Like "*[!A-Za-z]*" requires at least one character that is not a letter,
and the Not reverses that, thus forbidding any character that is not a
letter.

Users will be able to type anything but the validation rule will be
applied when they move away from the field (including trying to update
the record). If you want also to make it impossible to type incorrect
characters, put something like this in the KeyPress event handler of the
textbox that is displaying the field:

Select Case KeyAscii
Case 8, 9, 13 'Backspace, tab, enter: process these
'Do nothing
Case 65 to 90, 97 to 122 'A-Z, a-z
'Do nothing
Case Else
'supress the keystroke
KeyAscii = 0
End Select

Please help
how can i only allow user to type leters (like
christopher) only!! not characters (like chris%&her)

many thanks chris:)
 

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

Top