+ Reply to Thread
Results 1 to 9 of 9

Textbox masking confidential item input with hide & show button?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Portsmouth, VA now, Falmouth, VA 4 yrs, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    625

    Textbox masking confidential item input with hide & show button?

    Good Afternoon Everyone-

    Until a few days ago the last time i worked in Access (if i recall) was somewhere around 2011 or so, and since i have an issue remembering what happened even a few minutes ago, i'm close to starting at the beginning. Fortunately with the extreme help from people in the Excel forums here i have worked in that for a number of years, so i am not completely clueless... (just nearly clueless).

    I am putting together an Access project for a friend. We need to record customer Social Security Numbers (SSN) and Date of Birth (DoB).

    Best case would be a means similar to webpages where it could be entered with momentary visibility by character, then obscured, along with a Show/Hide button.

    Basically, to simultaneously use both the SSN and Date input masks, or replicate them in VBA.

    Seems to me there certainly is a solution out there, but i have become rather frustrated trying to find it - Would any of you good folks be able to point me in the right direction?

    Thank you for considering my problem and for your expertise and kindness!

    -Bruce

  2. #2
    Valued Forum Contributor
    Join Date
    09-18-2023
    Location
    Geogia, USA
    MS-Off Ver
    365
    Posts
    339

    Re: Textbox masking confidential item input with hide & show button?

    The TextBox has an InputMask property https://learn.microsoft.com/en-us/of...tbox.inputmask

    "Setting the InputMask property to the word "Password" creates a password-entry control. Any character typed in the control is stored as the character but is displayed as an asterisk (*). You use the Password input mask to prevent displaying the typed characters on the screen"

    Will that work for you, or do you need a more bespoke control for SSN and DOB?

  3. #3
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Portsmouth, VA now, Falmouth, VA 4 yrs, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    625

    Re: Textbox masking confidential item input with hide & show button?

    Thank you for replying!

    What i am looking for is a mask for the textbox like the ones for SSN and Date that will provide basic input formatting and restriction AND the obscuration of the password input mask AND the ability to turn the password mask on or off with a user command button or the like. Kind of wondering if the same HTML/Javascript or howevertheydoit code used on webpages can be somehow used in Access...

  4. #4
    Valued Forum Contributor
    Join Date
    09-18-2023
    Location
    Geogia, USA
    MS-Off Ver
    365
    Posts
    339

    Re: Textbox masking confidential item input with hide & show button?

    Okay, you could probably use VBA via the on keydown or keypress event of the textbox,
    the textbox does have a Social Security mask but that just sets it to 000-00-0000 without the ability to hide the numbers (that I could see)

    Perhaps combined with that and a bit of code to change the numbers to * (while keeping the actual value) and a toggle button.

    I'll play around with it some, if you'd like. In between my grandkids visiting :-)
    Attached Images Attached Images

  5. #5
    Valued Forum Contributor
    Join Date
    09-18-2023
    Location
    Geogia, USA
    MS-Off Ver
    365
    Posts
    339

    Re: Textbox masking confidential item input with hide & show button?

    I created some code to handle masking the SSN, you should be able to adapt it for the DOB.
    My form has a textbox called txtSSN and a button to toggle viewing masked or not.

    Private Sub btnToggleView_Click()
        
        ' switch between masked and clear view of the SSN
        txtSSN.SetFocus
        If Left(txtSSN.Text, 1) = "*" Then
            ' currently displaying masked view, switch to clear view
            btnToggleView.Caption = "Hide"
            UpdateTextBox txtSSN, Len(txtSSN.Text), True
        Else
            ' switch the clear view back to masked
            btnToggleView.Caption = "View"
            UpdateTextBox txtSSN, Len(txtSSN.Text)
        
        End If
    End Sub
    
    Private Sub Form_Load()
        
        ' when the form is displayed, make sure things are cleared
        txtSSN.SetFocus
        txtSSN.Text = ""
        txtSSN.Tag = ""
        
        btnToggleView.Enabled = False
            
    End Sub
    
    Private Function MaskSSN() As String
    
        ' change all the numbers to *
        Dim x As Integer
        Dim maskedSSN As String
        
        For x = 1 To Len(txtSSN.Tag)
            If x = 4 Or x = 7 Then
                ' add the dash
                maskedSSN = maskedSSN & "-"
            Else
                maskedSSN = maskedSSN & "*"
            End If
        Next x
        
        MaskSSN = maskedSSN
        
    End Function
    
    Private Sub UpdateTextBox(ByRef txtBox As TextBox, PositionOfCursor As Integer, Optional unMask As Boolean)
    
        ' display the post masked data
        txtBox.Text = ""
        
        If unMask Then txtBox.Text = txtBox.Tag Else txtBox.Text = MaskSSN()
        
        ' position the cursor in the textbox
        txtBox.SelStart = PositionOfCursor
        txtBox.SelLength = 0
        
        DoEvents
    
    End Sub
    
    Private Sub DeleteTheCharacterAt(ByRef txtBox As TextBox)
    
        ' remove the character at the current position of the textbox passed
        txtBox.Tag = Left(txtBox.Tag, txtBox.SelStart) & Mid(txtBox.Tag, txtBox.SelStart + 2)
        
        DoEvents
    Exit Sub
    
    End Sub
    
    Private Sub txtSSN_KeyUp(KeyCode As Integer, Shift As Integer)
        
        Dim KeyAscii As Integer
        
        If KeyCode >= 96 And KeyCode <= 105 Then
            ' these are the number pad numbers
            ' this is needed because KeyCode is not the Ascii representation of the key
            ' but the number on the keyboard
            KeyAscii = KeyCode - 48
        Else
            ' some KeyCode and their ascii values are the same though
            KeyAscii = KeyCode
        End If
        
        Select Case KeyAscii
               
            Case 8, 46 ' backspace or delete key pressed
            
                DeleteTheCharacterAt txtSSN
                
            Case 48 To 57 ' a number 0 through 9 using the top keys
    
                ' this is the max length of a SSN, ignore the input
                If Len(txtSSN.Tag) = 11 Then
                    ' remove the 12th character by re-applying the completed SSN
                    UpdateTextBox txtSSN, 11
    
                    Exit Sub
                End If
    
                If txtSSN.SelStart >= Len(txtSSN.Tag) Then
                    ' keep the actual numbers to save in the DB in the tag property
                    txtSSN.Tag = txtSSN.Tag & Chr(KeyAscii)
    
                    ' automatically add the dashes
                    If Len(txtSSN.Tag) = 3 Or Len(txtSSN.Tag) = 6 Then
                        txtSSN.Tag = txtSSN.Tag & "-"
                    End If
    
                    UpdateTextBox txtSSN, Len(txtSSN.Tag)
    
                Else
                    ' inserting a number after a backspace or an arrow
                    ' moved the cursor
                    txtSSN.Tag = Left(txtSSN.Tag, txtSSN.SelStart - 1) & Chr(KeyAscii) & Mid(txtSSN.Tag, txtSSN.SelStart)
    
                    UpdateTextBox txtSSN, txtSSN.SelStart
    
                End If
    
            Case Else ' do nothing
            
        End Select
        
        btnToggleView.Enabled = (Len(txtSSN.Text) > 0)
        
    End Sub

  6. #6
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Portsmouth, VA now, Falmouth, VA 4 yrs, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    625

    Re: Textbox masking confidential item input with hide & show button?

    I'm finally at the point of being about to implement this.

    I had switched focus from worrying over the details to building the structure, and this project took a heck of a lot of hours more than i thought it would eat up - as i've got a family and for some reason wasn't born rich, am not bright enough to become rich and have not yet won the Publisher's Clearing House lottery (...), i've had to squeeze it in when i can...

    I am looking forward to working with the code you graciously provided and reporting back.

    Thank you!

    -Bruce

  7. #7
    Valued Forum Contributor
    Join Date
    09-18-2023
    Location
    Geogia, USA
    MS-Off Ver
    365
    Posts
    339

    Re: Textbox masking confidential item input with hide & show button?

    Quote Originally Posted by brucemc777 View Post
    I'm finally at the point of being about to implement this.

    I had switched focus from worrying over the details to building the structure, and this project took a heck of a lot of hours more than i thought it would eat up - as i've got a family and for some reason wasn't born rich, am not bright enough to become rich and have not yet won the Publisher's Clearing House lottery (...), i've had to squeeze it in when i can...

    I am looking forward to working with the code you graciously provided and reporting back.

    Thank you!

    -Bruce
    hahaha wasn't born rich, I heard that! I hope this helps and works out the way you need it to.

  8. #8
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Portsmouth, VA now, Falmouth, VA 4 yrs, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    625

    Re: Textbox masking confidential item input with hide & show button?

    Frankly, i am thrilled with it. Not only does it do everything i wanted, but i am learning from how you code. The sequential blocks make my coding look, well, like spaghetti. Thank you VERY much!

  9. #9
    Valued Forum Contributor
    Join Date
    09-18-2023
    Location
    Geogia, USA
    MS-Off Ver
    365
    Posts
    339

    Re: Textbox masking confidential item input with hide & show button?

    You are very welcome, happy to lend a hand!

    Good luck with the rest of your project.

+ 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. [SOLVED] Using an Option Button and another button to hide/show lines
    By dharvey1978 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2021, 06:13 PM
  2. Replies: 4
    Last Post: 12-11-2018, 01:11 PM
  3. [SOLVED] Hide or disable option button or show empty graph when slicer item has no data on userform
    By Raylou in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-05-2018, 05:24 AM
  4. Replies: 6
    Last Post: 08-31-2017, 12:16 PM
  5. VBA hide row based on pull down with button to toggle show/hide
    By myronr in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-12-2012, 06:07 PM
  6. Masking an input box?
    By british.assassi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-18-2005, 02:25 PM
  7. [SOLVED] Masking on TextBox
    By Santiago in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2005, 05:05 PM

Tags for this Thread

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