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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Allow Letter Entry A-Z Only 2

Status
Not open for further replies.

phbarbara

Technical User
May 16, 2002
10
US
I need to limit the entry of characters in the LName and FName fields of a database table. I would like the only allowable entries to be a-z, -, to allow hyphenated last names, and a space for names like St Mary. The field needs to be upper or lowercase and limited in length only by the field size. How do I format this? There is a staff member that continues to add their own embellishments to names making it difficult to sort and query! I'm not a programmer but can cut and paste code and change field names and object names to meet my needs. Thanks.
 
Hi,
Search for the topics below in your Access help file

"About creating input masks to control how data is entered in a field or control"
"Input mask syntax and examples"
"InputMask Property"

regards

Zameer Abdulla
 
GOF52

This is a little tricky.

Try using the OnKeyPress event procedure.

When a key is typed, you can evaluate it...
- Check to make sure it is alphabetic, or accepted special character.
- Count characters
- Even use formal text (upper case first letter, small case for the rest)

It takes a bit of work, but is do-able.

Richard
 
Another approach to consider is to put some code in the Before_Update event of the control

You can then add all sorts of checking and if a check fails you can add msgbox comments to tell the user the exact problem.

Something like
Code:
Dim intC as Integer
Dim ascChar as Integer

For intC = 1 To Len(txtBoxName)
ascChar = Asc(Mid(txtBoxName,intC,1))

If ascChar = 32 Then ' Its a space Char
    ' Char is acceptable
ElseIf ascChar = xx ' Whats the Ascii for "-"
    ' Char is acceptable
ElseIf (ascChar > 64 And ascChar < 91) _
    ' Char is acceptable
ElseIf (ascChar > 96 And ascChar < 123) Then
    ' Char is acceptable
Else
    MsgBox "Inappropriate character in position " & intC & vblf _
         & "Your entry has not been accepted.", ,"Please concentrate"
    Cancel = True
End If

' add other checks here if you want to.

Next


'ope-that-'elps.



G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Thank you for your replies. The request was beyond the scope of an input mask but thanks for the thought. The OnKeyPress event sounds quite reasonable but I don't know if I could figure that one out! The code I can use, thank you Little/Smudge.
 
Thanks for the feedback GOF52 - thats a good roundup of the various ideas and how applicable they were to your needs. It provides feedback on how useful you found the ideas.

That way we all learn. :)






G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top