Is there a way to limit the characters entered into a field to
just Capital A to Z and an _
?
I did a search here and either didn’t use the right phrase or no one asked before.
Thanks,
Scott
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Limit input characters (Access97)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Limit input characters (Access97)
- This topic has 14 replies, 5 voices, and was last updated 22 years, 11 months ago.
AuthorTopicWSready4data
AskWoody LoungerJune 10, 2002 at 5:00 pm #372094Viewing 0 reply threadsAuthorReplies-
WSGARYPSWANSON
AskWoody Lounger -
WSready4data
AskWoody Lounger -
WSCecilia
AskWoody Lounger -
WSready4data
AskWoody LoungerJune 10, 2002 at 7:33 pm #593671Cecilia,
Not an Input mask. I want to restrict the user from entering other than A to Z or an underscore.
I don’t want them to be able to enter a * ,& , %, any other punctuation, or a space.
The input is used in some code to generate some tables and do some other processing and the non alphabet characters cause errors.
Scott -
WSCecilia
AskWoody Lounger -
WSready4data
AskWoody LoungerJune 10, 2002 at 7:55 pm #593675Looking for code in the BeforeUpdate event to check for the conditions listed above.
I could do it with a select case stmt but I would have to have it check for all the characters in the string
except the ones that I wanted. Or use instr to search for everything I don’t want.
I was looking for an easier way.
Maybe I’m not explaining myself clear enough. If input A to Z or _, msgbox “Use only A to Z or _” -
WSGARYPSWANSON
AskWoody Lounger -
WSCecilia
AskWoody LoungerJune 10, 2002 at 11:42 pm #593701Okay, I realize that you don’t want an input mask, but now I’m asking you….What does this code do that an input mask doesn’t?
For example, if I use as my input mask LLLLL (or ?????), then the user must enter (at least) five letters. (AAAAA will require (aaaaa is entry optional) five letters or numbers, excluding symbols.) Isn’t that what you’re after? To prevent the user from entering anything but exactly what you want? What is the benefit to doing this in code?
Just curious,
Cecilia
-
WSready4data
AskWoody LoungerJune 11, 2002 at 12:08 am #593706 -
WSCecilia
AskWoody LoungerJune 11, 2002 at 1:49 am #593715How about checking the characters by their chr codes?
Numbers start at chr(48) through chr(57), letters are chr(65) through chr(90) and chr(97) through (122), underscore is chr(94). You could either validate by going through each of these in a loop or use the before update to check the string.
Just an idea to make up for my dumbness earlier today
Cecilia
-
WScharlotte
AskWoody LoungerJune 11, 2002 at 2:50 am #593732Depending on how much data is going to be typed into the field, you can use the OnChange event to test every character typed into the control to validate it against a set of criteria. OnChange happens before BeforeUpdate and AfterUpdate, and it allows you to validate as you go along.
Otherwise, you can use the InStr function in the BeforeUpdate event of the control to test and see if a string contains a particular character, either using the Ascii value of the character or just using a text string like ” ” for a space.
Still another option is to step through the characters one at a time, testing each against the range of valid characters with a Select Case. You can also use Ucase() to force the entered value to upper case.
-
WSHansV
AskWoody LoungerJune 11, 2002 at 5:53 am #593768You might use the KeyPress event of the text box:
Private Sub txtMyField_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 8, 65 To 90, 95
‘ Backspace, upper case, underscore OK
Case 97 To 122
‘ Convert lower case to upper case
KeyAscii = KeyAscii – 32
Case Else
‘ Ignore the rest
KeyAscii = 0
End Select
End Sub -
WSready4data
AskWoody Lounger
-
-
-
WSGARYPSWANSON
AskWoody LoungerJune 10, 2002 at 7:58 pm #593677Is sounds as if you want to keep the characters entered from A to Z or an underscore even if the length of the field changes.
I would suggest that on the after update or on change event of the parameter entered on the form that you launch a function that reviews the data for “invalid” characters. If the characters are invalid, stop the VBA processing and provide a message box to the user to re-insert the characters.
A function similar to this may work.
Function SubC1(strMyString As String) As String
If InStr(strMyString, “-“) > 0 Then MsgBox “ERROR” ‘Check for invalid character(s)
SubC1 = strMyStringEnd Function
You will need to add additional invalid parameters. You could also loop through the text to check it as well.
Hope this helps or gives you some ideas. I wonder if you could put this code on the validation line of the form where the data is being entered??
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Xfinity home internet
by
MrJimPhelps
2 hours, 47 minutes ago -
Convert PowerPoint presentation to Impress
by
RetiredGeek
4 hours, 46 minutes ago -
Debian 12.11 released
by
Alex5723
13 hours, 13 minutes ago -
Microsoft: Troubleshoot problems updating Windows
by
Alex5723
16 hours, 54 minutes ago -
Woman Files for Divorce After ChatGPT “Reads” Husband’s Coffee Cup
by
Alex5723
3 hours, 17 minutes ago -
Moving fwd, Win 11 Pro,, which is best? Lenovo refurb
by
Deo
13 hours, 22 minutes ago -
DBOS Advanced Network Analysis
by
Kathy Stevens
1 day, 9 hours ago -
Microsoft Edge Launching Automatically?
by
healeyinpa
1 day ago -
Google Chrome to block admin-level browser launches for better security
by
Alex5723
1 day, 12 hours ago -
iPhone SE2 Stolen Device Protection
by
Rick Corbett
1 day, 4 hours ago -
Some advice for managing my wireless internet gateway
by
LHiggins
12 hours, 18 minutes ago -
NO POWER IN KEYBOARD OR MOUSE
by
HE48AEEXX77WEN4Edbtm
5 hours, 10 minutes ago -
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
1 day, 21 hours ago -
Sometimes I wonder about these bots
by
Susan Bradley
1 day, 18 hours ago -
Does windows update component store “self heal”?
by
Mike Cross
1 day, 8 hours ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
2 days, 11 hours ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
19 hours, 53 minutes ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
8 hours, 31 minutes ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
2 days, 14 hours ago -
Windows 10 Build 19045.5912 (22H2) to Release Preview Channel
by
joep517
2 days, 14 hours ago -
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
2 days, 3 hours ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
2 days, 22 hours ago -
0Patch, where to begin
by
cassel23
2 days, 16 hours ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
3 days, 12 hours ago -
89 million Steam account details just got leaked,
by
Alex5723
3 days ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
3 days, 20 hours ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
3 days, 11 hours ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
14 hours, 8 minutes ago -
Installer program can’t read my registry
by
Peobody
6 hours, 2 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
3 days, 9 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.