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

Format a Field: Allow Letters Only

Status
Not open for further replies.

bostonfrog

Programmer
Jul 14, 2003
79
0
0
MX
I looked through this forum as well as Access Help but still can't find the answer on how to do this. I want to format a field in a table to only allow text (a,b,c,d,e, etc.) or capitilizations of letters -- no numbers or symbols. I only want data entry people to enter "letters" in the FirstName of LastName fields of a table. Can one do this? It just occurred to me that some names might be "O'Connor" or "O'Leary" with an apostrophe. I wonder if I can work around that too.
 
Look in Help under "input mask"
too much to copy and paste here
tons of examples though

DougP, MCP
 
Here is a Sub proceedure that will accomplish what you desire.

Private Sub NameOfYourField_KeyPress(KeyAscii As Integer)
'Allows only capital letters spaces, hyphens, apostrophies and ampersands in this field
'backspace = 8
'Enter Key (Carriage Return) = 13
'space = 32
'ampersand = 38
'apostrophies = 39
'hyphen = 45
'Delete Key = 127
Dim myChr As Integer
Dim myChr_flg As Integer: myChr_flg = 0
myChr = KeyAscii
If (myChr > 96 And myChr < 123) Then myChr = myChr - 32
If (myChr > 64 And myChr < 91) Or _
myChr = 8 Or _
myChr = 13 Or _
myChr = 32 Or _
myChr = 38 Or _
myChr = 39 Or _
myChr = 45 Or _
myChr = 127 Then _
myChr = myChr: myChr_flg = 1
If myChr_flg = 0 Then myChr = 0
KeyAscii = myChr
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top