VALIDATION PROBLEM (1 Viewer)

B

BADAVEG

Guest
OK friends, I'm new to Access so nobody laugh when you read this. I'm trying to create a table which includes a "last name" field. Of course it's a text field, and I want to allow just letters and a "dash" (hyphen), since many last names are hyphenated. My problem is, how do I get the hyphen in and not allow any other special characters (or numbers)? I tried an input mask to allow just alpha characters, but then of course the dash isn't allowed. To allow input of the dash I changed the mask to 'C's but that permits ANY character, which you sure don't want in a name. So how do I set the field up for JUST alpha characters and only the special character of dash? (Is it possible to keep the C's in my input mask but create some validation that weeds aout all numbers and the other special characters? If so, would somebody please fill me in before I have a nervous breakdown or heart attack?). MS Help is NOT much help when it comes to validating.
Related question: I'm in my cubicle spending half the day trying to solve this thing through trial-and-error, because I don't understand how to create validations. Is there some book(s) someone can recommend that goes into DETAIL about how validations are created, how to build expressions, and especially how all the functions that can be used for validating work. Like I said, MS Help just doesn't give you much. (If all this is located in more than one source, please provide as many as you can).

Signed

About to Lose it in Chicago
 

SimonC

Registered User.
Local time
Today, 08:50
Joined
Feb 25, 2002
Messages
48
Your best bet might be the KeyPress event of the LastName text box. You get passed a value KeyAscii which contains the Ascii code of the key pressed. You'll want to allow through the upper- and lower-case alphabetic characters (65 to 90 and 97 to 122) plus a hyphen (45) and maybe a space (32). Whether you also allow accented characters through for foreign names is up to you.

If a key is pressed that isn't valid, just set KeyAscii to 0.

Simon.
 
B

BADAVEG

Guest
Thanks Simon, when I get to work I'll try this right away and let you know how it goes.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 04:50
Joined
Feb 19, 2002
Messages
42,981
You will also need to allow the apostrophe to accomodate names such as O'Brien.
 
B

BADAVEG

Guest
Thanks SimonC, it worked like a charm! And Pat you're absolutely right--I didn't think of the apostrophe. Gotta go back tomorrow and fix that.
 

Users who are viewing this thread

Top Bottom