If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Validation rules
Please help
how can i only allow user to type leters (like christopher) only!! not characters (like chris%&her) many thanks chris |
#2
|
|||
|
|||
Validation rules
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 "Chris Lee" wrote in message ... Please help how can i only allow user to type leters (like christopher) only!! not characters (like chris%&her) many thanks chris |
#3
|
|||
|
|||
Validation rules
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 On Wed, 28 Apr 2004 19:06:41 -0700, "Chris Lee" wrote: Please help how can i only allow user to type leters (like christopher) only!! not characters (like chris%&her) many thanks chris -- John Nurick [Microsoft Access MVP] Please respond in the newgroup and not by email. |
#4
|
|||
|
|||
Validation rules
cool, both - thanks John!
"John Nurick" wrote in message ... 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 On Wed, 28 Apr 2004 19:06:41 -0700, "Chris Lee" wrote: Please help how can i only allow user to type leters (like christopher) only!! not characters (like chris%&her) many thanks chris -- John Nurick [Microsoft Access MVP] Please respond in the newgroup and not by email. |
Thread Tools | |
Display Modes | |
|
|