By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
463,085 Members | 636 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 463,085 IT Pros & Developers. It's quick & easy.

excluding characters input to a textbox

P: 1
I am trying to create a password entry textbox on a form.
I would like to not allow single quotes, double quotes, the pound sign, ... etc. but want to accept other printable characters. I want the value of the textbox to be used as a string.

How can I check for the invalid characters, ignore them or tell my user the character is not allowed, but continue to get entered characters until the user has finished entering a password?
Jun 12 '14 #1
Share this Question
Share on Google+
4 Replies

Expert 100+
P: 1,244
Here's one way to ignore them. In the AfterUpdate event of the password object you can add this VBA:
Expand|Select|Wrap|Line Numbers
  1. me.password_txt =replace(replace(replace(me.password_txt,"'",""),"#",""),chr(34),"")
That will eliminate single quote, double quote and # from the entered password.

You can also look at various ways to use the validation property of the textbox.

Jun 12 '14 #2

Expert Mod 2.5K+
P: 3,542
Erkano Timenon,

Welcome to Bytes!

I would begin by attaching some code to the OnKeyPress Event of the Text Box control. That code would evaluate the last key press of the User, then truncate the string by one character if it was an invalid character. If it was a valid character, there would be no action and the user could continue to enter text.

Play around with it and if you come up with some road blocks in your code, let us know and we will try to help you walk through it.
Jun 12 '14 #3

Expert 100+
P: 1,244
I like that solution, twinnyto. It's also real good stuff for a newbie to learn.
Jun 12 '14 #4

Expert Mod 15k+
P: 31,770
Be very careful how you handle special characters :- For instance the cursor movement keys or the (destructive) backspace key.
Jun 29 '14 #5

Post your reply

Sign in to post your reply or Sign up for a free account.