excluding characters input to a textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Erkano Timenon
    New Member
    • Jun 2014
    • 1

    excluding characters input to a textbox

    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?
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    Here's one way to ignore them. In the AfterUpdate event of the password object you can add this VBA:
    Code:
    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.

    Jim

    Comment

    • twinnyfo
      Recognized Expert Moderator Specialist
      • Nov 2011
      • 3662

      #3
      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.

      Comment

      • jimatqsi
        Moderator Top Contributor
        • Oct 2006
        • 1293

        #4
        I like that solution, twinnyto. It's also real good stuff for a newbie to learn.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          Be very careful how you handle special characters :- For instance the cursor movement keys or the (destructive) backspace key.

          Comment

          Working...