Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2007

    Unanswered: How do I mask an input password

    I created an inputbox for password in msaccess form but i dont want the password to be displayed when it is entered.

  2. #2
    Join Date
    Jan 2007
    Provided Answers: 10
    Set the input mask to "PASSWORD"..?
    Home | Blog

  3. #3
    Join Date
    Nov 2003
    Now...I'm not really sure about MS-Access over 2000 but the Access InputBox does not contain any method for masking the input text (while it's typed). The Access TextBox however does contain this feature as I'm sure you are already aware.

    What most tend to do (and for one good reason comes to mind) is to make a
    Password Form and utilize the typical TextBox with Input Mask property set to Password as George has already suggested. As you can see below, to do this with code is rather extensive (to some degree). It's simply less time consuming to just make a new Form......for some.

    Anywho........, A lot of people think this is impossible buuuut;

    If you're just absolutely bent over backwards on using the MS-Access VBA
    InputBox then get ready to add a wee bit of code to your database application. The trick we need to carry out here is to Hook the keystrokes to the InputBox and make them look like something else...gee...maybe an asterisk (or whatever - the choice is yours) but return the actual string typed as something we can make heads or tails of (use). We use a simple API Timer to carry out this task which will ultimately be killed when the Enter key is pressed or the OK/CANCEL buttons are selected within the InputBox (hmmm...a the possibilities are spinning around yer head, right ). This Timer works in conjunction with the AddressOf

    There are a couple of ways we can attack this.

    Function which ultimately fires our custom Hook Function which does all the work blah blah blah... 1) We can create a alternate
    InputBox Function perhaps called InputBoxMMask') so as to reduce the amount of code required to call the InputBox. You never may want to use this feature within several areas of your Database application. Because we are using a (M for 'with API Timer (SetTimer from the user32.dll), we need to fire that up first before we fire the InputBox. By simply placing this step into a custom Function we can eliminate that step all together along with a few other necessary items.

    2) Just use the
    InputBox as you normally would but add a call to the API Timer before you use the InputBox.

    Options for either method are provided here. I have also attached a small MS-Access (2K) sample application so you can quickly see first hand how this works (any criticism is absolutely.........not welcome - just kidding).

    First off, we need to create a new Database Code Module. Name it
    'InputBoxTextMask' so that you know what the module does. You could blend the following code within an existing Database Code Module but I recommend you keep it separate. It's nice to know what modules are really doing...what. Copy and Paste the following code into your new Database Code Module (do not place this code into a Form Code Module):

    Option Compare Database
    Option Explicit
    'Declare Variables we need.
    Global IB_Msg As String        'The Prompt Text you'll see in the InputBox.
    Global IB_Title As String       'Title for the InputBox.
    'The API Functions we need to make this stuff work.
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
                                            (ByVal lpClassName As String, _
                                            ByVal lpWindowName As String) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
                                              (ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
                                              ByVal lpsz1 As String, ByVal lpsz2 As String) _
                                              As Long
    Public Declare Function SetTimer& Lib "user32" (ByVal hwnd&, ByVal nIDEvent&, _
                                          ByVal uElapse&, ByVal lpTimerFunc&)
    Public Declare Function KillTimer& Lib "user32" (ByVal hwnd&, ByVal nIDEvent&)
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
                                             ByVal wMsg As Long, ByVal wParam As Long, _
                                             lParam As Any) As Long
    ' Constants for the Above API's.
    Private Const IB_SETPASSWORDCHAR = &HCC    'Used with the SendMessage API
    Public Const IB_INPUTBOX As Long = &H5000& 'Used with the SetTimer API
    Private Const IB_ATOM = "#32770"           'The classname Atom of the InputBox
    Private MaskCharacter As String   'Will hold our Mask Character.
    Public Function HookInputBox(ByVal IBHwnd As Long, ByVal MsgPtr As Long, _
                                ByVal EventID As Long, ByVal EventWTime As Long) As Long
                    'Now...Don't piss around in here unless you know what you're doing.
      Dim IBMsgHwnd As Long, IBEHwnd As Long
      'Check to see if there is something held within the MaskCharacter String
      'Type Variable. If there isn't then place an Asterisk there. The MaskCharacter
      'Variable actually holds the character that will be displayed when a user types
      'characters into the InputBox.
      If Len(MaskCharacter) = 0 Then MaskCharacter = "*"
      IBMsgHwnd = FindWindowEx(FindWindow(IB_ATOM, "[IB_Msg]"), 0, "Edit", "")
      IBEHwnd = FindWindowEx(FindWindow(IB_ATOM, IB_Title), 0, "Edit", "")
      'Below we use the SendMessage API Function to send the
      'Mask character we want to the displayed InputBox.
      'Notice we are using the asterisk (*) here as the Mask
      'Character within the Asc() Function. You can place
      'whatever character you like here.
      Call SendMessage(IBEHwnd, IB_SETPASSWORDCHAR, Asc(MaskCharacter), 0)
      'Destroy the timer when the InputBox is closed either
      'by the Enter key, the OK button or the Cancel button.
      KillTimer IBHwnd, EventID
    End Function
    Public Function InputBoxM(ByVal IBPromptMsg As String, Optional ByVal IBTitle As String, _
                              Optional ByVal MaskChar As String = "*") As String
      Dim Ret As Long
      Dim Frm As Form
      IB_Msg = IBPromptMsg
      If IsMissing(IBTitle) Then IBTitle = Application.CurrentProject.Name
      MaskCharacter = MaskChar
      IB_Title = IBTitle
      Set Frm = Application.Screen.ActiveForm
      Ret = SetTimer(Frm.hwnd, IB_INPUTBOX, 1, AddressOf HookInputBox)
      InputBoxM = InputBox(IBPromptMsg, IBTitle)
      MaskCharacter = ""
    End Function

    It's really not a lot of code and if you never plan to use the custom
    InputBoxM Function (as we talked about earlier) then you can delete the Function from within the new code module. I personally find it easier to use the InputBoxM Function but then again, each to their own. If you want to use other InputBox features other than the Prompt Message and InputBox Title then the InPutBoxM Function will be no good to you unless you modify it somewhat.

    Now to use
    InputBox as you normally would, just use something like the code below (try it in the OnClick event of a Command button:

      Dim Ret As Long
      Dim RetMsg As String
      'The IB_Title and IB_Msg String Type Variables MUST be filled and
      'supplied to the InputBox. These a Global variables and are used
      'by the FindWindow and FindWindowEx API functions located in the
      'InputBoxTextMask Database Code Module.
      IB_Title = "Password Required...."
      IB_Msg = "This particular section of the Database requires Password Entry." & _
               vbNewLine & vbNewLine & "Please Enter Your Password:"
      'You MUST start the API Timer below BEFORE the InputBox is initiated.
      Ret = SetTimer(Me.hwnd, IB_INPUTBOX, 1, AddressOf HookInputBox)
      RetMsg = InputBox(IB_Msg, IB_Title)
      MsgBox "The Password You supplied is:    " & vbNewLine & vbNewLine & RetMsg, _
             vbInformation, "String From InputBox "
  do the same task using the
    InputBoxM custom Function, we merely do this:

    Dim RetMsg As String
    RetMsg =
     InputBoxM("This particular section of the " & _
                       "Database requires Password Entry." & vbNewLine & vbNewLine & _
                       "Please Enter " & "Your Password:", "Password Required....","*")
    MsgBox "The Password You supplied is:    " & vbNewLine & vbNewLine & RetMsg, _
           vbInformation, "String From InputBox "


    The edit feature of this forum blow chunks
    Attached Files Attached Files
    Last edited by CyberLynx; 09-08-07 at 07:42.
    Self Taught In ALL Environments.....And It Shows!

  4. #4
    Join Date
    Nov 2003
    continued from post above..............


     MsgBox "The Password You supplied is:    " & vbNewLine & vbNewLine & _
           InputBoxM("This particular section of the Database requires " & _
           "Password Entry." & vbNewLine & vbNewLine & "Please Enter " & _
           "Your Password:", "Password Required....", "*"), vbInformation, _
           "String From InputBox "

    Notice the Asterisk (
    *) within the last parameter of the InputBoxM Function. This is the character we are passing along to use as the Mask Character. This is the character users will see when entering data into theInputBox You can supply any SINGLE character you like here.

    OK...Now ya'll tell me which is the greater pain. Create a Password Form and have to use some code and resources or, use a wee bit of code. I personally use both and it's only because in some applications I just find the InputBox to be a little.....bland.

    Did you find all this amusing?.....then tell it to your local politician.
    See, this is what happens when yer on holidays and bored.

    Last edited by CyberLynx; 09-08-07 at 07:31.
    Self Taught In ALL Environments.....And It Shows!

Posting Permissions

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