+ Reply to Thread
Results 1 to 3 of 3

Masked Control Textbox entry field - backspace not working right

  1. #1
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Masked Control Textbox entry field - backspace not working right

    So, I have been able to piece together code from a few different searches to create a TextBox that mimics the masking functionality in Access, where only numeric values are accepted into the underscored sections of the "mask" text the textbox starts out populated with.


    My desired data format for the entered value is a 4 digit number, a dash, and a single digit number (the single digit will usually, but not always, be a "1"):

    Mask text:

    ____-_

    Sample allowed values:
    0001-1
    0023-1
    0106-2
    1002-1
    0074-1

    etc...

    It's working, but I would like the ability to backspace one character at a time, and the code (in sample file version 1) resets the whole field to the default "mask" text on a single "backspace" (or "delete") keystroke.

    Here's the code:

    Please Login or Register  to view this content.
    I pretty much follow what's going on in the code, and figured out that if I make the following changes to the KeyDown event sub (as seen in sample file version 2), the backspace key works correctly until you get to the "-", and then it only works on the single digit after the "-". Also, if you type in 2 or more digits and then click in between them, the backspace acts real goofy, inserting "-"s where they shouldn't be and just generally wreaking all kinds of havok, and without leaving the "If keycode = 46..." statement to allow the delete key to function, you can't even clear it out and start over. It's a mess.


    My experimental changes:
    Please Login or Register  to view this content.
    Is there a way to have the backspace key correctly back up one space and replace the digit with an underscore, regardless of where it is in the string, skipping over the "-" in the same way that the cursor jumps the "-" when typing the number in?

    Bonus points if you can also add a msgbox that prevents exiting the textbox without typing all 5 digits in the number... Maybe on an exit event, with an If statement that checks for any "_" characters in the TBcutfile.Value string (I don't know how to do that check)? I could try to catch that in the error validation section of the full code, but a lock on the textbox at time of entry would be a little cleaner on the user end. And, I'd still need to know how to look for any "_"s in the string... But that might be a question for a separate thread, or something else I can google.

    Thanks in advance!
    Attached Files Attached Files

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Masked Control Textbox entry field - backspace not working right

    Hello Arnold Layne,

    What is your objective with using the userform? When a user has entered the correct "Password" with you requested Backspace, what should happen next? There is no "Go" or "Continue" or "Exit" Button.

    The TextBox in itself has a feature under Properties to mask any Password. Why not just use that?

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: Masked Control Textbox entry field - backspace not working right

    Winon, this is a sample file just demonstrating the TextBox functionality I'm working on. It's a field for entering a filename on a much larger program designed for tracking material use at a sign shop. The full program collects various information including the cutter's name, the file number (in the textbox I'm working on now), material type, job information, and so on.


    I'm not trying to hide the input, the "masking" I'm referring is like when you are entering a date or a phone number on a website and the field starts out as __/__/____ or (___)-___-____, and you can only type in numbers where the underscores are. The sample file version 1 works like it should, but you can only delete the entire entry, you can't backspace through it one digit at a time to make a correction if you mistype. That's what I'd like to achieve. Version 2 got me close, but introduced some undesired behaviors. Play around with that version and you'll see what I'm talking about. If you type in the full number and then try to backspace, you can only clear the single digit after the "-", and if you click the cursor into the middle of what you entered, then the backspace key screws everything up.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 01-18-2018, 01:49 PM
  2. [SOLVED] How to allow TextBox backspace key?
    By VAer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2017, 09:34 AM
  3. [SOLVED] How to clear all text form textbox with one backspace (userform)
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-16-2017, 12:36 PM
  4. add a string of locked text to vba textbox based on entry in the same textbox
    By yoursamrit2000 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-21-2014, 11:48 PM
  5. [SOLVED] Narrowing Results in ListBox using TextBox that Reloads when Backspace is Struck
    By kak132 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-24-2014, 12:10 PM
  6. [SOLVED] UserForm TextBox Conditional Masked Format
    By saucey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-20-2012, 12:14 PM
  7. Replies: 2
    Last Post: 07-09-2012, 02:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1