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
-
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
32 minutes ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
1 hour, 38 minutes ago -
0Patch, where to begin
by
cassel23
1 hour, 24 minutes ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
15 hours, 16 minutes ago -
89 million Steam account details just got leaked,
by
Alex5723
3 hours, 2 minutes ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
23 hours, 49 minutes ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
14 hours, 48 minutes ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
1 hour, 55 minutes ago -
Installer program can’t read my registry
by
Peobody
2 hours, 48 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
12 hours, 35 minutes ago -
Intel : CVE-2024-45332, CVE-2024-43420, CVE-2025-20623
by
Alex5723
19 hours, 55 minutes ago -
False error message from eMClient
by
WSSebastian42
1 day, 10 hours ago -
Awoke to a rebooted Mac (crashed?)
by
rebop2020
1 day, 20 hours ago -
Office 2021 Perpetual for Mac
by
rebop2020
1 day, 21 hours ago -
AutoSave is for Microsoft, not for you
by
Will Fastie
17 hours, 50 minutes ago -
Difface : Reconstruction of 3D Human Facial Images from DNA Sequence
by
Alex5723
2 days ago -
Seven things we learned from WhatsApp vs. NSO Group spyware lawsuit
by
Alex5723
1 day, 1 hour ago -
Outdated Laptop
by
jdamkeene
2 days, 6 hours ago -
Updating Keepass2Android
by
CBFPD-Chief115
2 days, 11 hours ago -
Another big Microsoft layoff
by
Charlie
2 days, 11 hours ago -
PowerShell to detect NPU – Testers Needed
by
RetiredGeek
8 hours, 39 minutes ago -
May 2025 updates are out
by
Susan Bradley
10 hours, 32 minutes ago -
Windows 11 Insider Preview build 26200.5600 released to DEV
by
joep517
2 days, 17 hours ago -
Windows 11 Insider Preview build 26120.3964 (24H2) released to BETA
by
joep517
2 days, 17 hours ago -
Drivers suggested via Windows Update
by
Tex265
2 days, 17 hours ago -
Thunderbird release notes for 128 esr have disappeared
by
EricB
13 hours, 15 minutes ago -
CISA mutes own website, shifts routine cyber alerts to X, RSS, email
by
Nibbled To Death By Ducks
3 days ago -
Apple releases 18.5
by
Susan Bradley
2 days, 18 hours ago -
Fedora Linux 40 will go end of life for updates and support on 2025-05-13.
by
Alex5723
3 days, 1 hour ago -
How a new type of AI is helping police skirt facial recognition bans
by
Alex5723
3 days, 2 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.