Results 1 to 8 of 8
  1. #1
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185

    Question Code to show PW as ******

    Here is the code I am currently using to require a PW on a button on click event



    Code:
    Dim PassWord As String    
    PassWord = InputBox("Enter Password")    
    If PassWord = "MYPassword" Then       
    ' Open Form       
    DoCmd.OpenForm "MYFormName" 
    DoCmd.GoToRecord , , acNewRec    
    Else       
    MsgBox ("You're not authorized")    
    End If
    Currently as the password is being typed, the actual key strokes are being shown.
    Is there something I can add to this code to have the keystrokes show up as ****** as it is being typed?

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    I typically use a wrapped form instead of an InputBox:

    http://www.baldyweb.com/WrappedForm.htm

    but I have heard of a way of getting a password mask into an InputBox:

    http://www.tek-tips.com/faqs.cfm?fid=4617
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Your second link takes me to forum where another link takes me to Daniels page but there is no information on the subject showing.

  4. #4
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Im having a hard time understanding the wrapped form concept.

    Code:
    Private Sub cmdTest_Click()
    Dim sPassword As String  
    sPassword = GetPassword()
    MsgBox "You entered: " & sPassword
     End Sub
    If I wanted the PW to be ABCD1234 as the initial password and then give the user the option to change his/her password what would I have to do and would you please give an example of the code?

  5. #5
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Ok, I did find this code to be able to hide the PW in an inputbox. but I keep getting the error,

    "The expression On Open you entered as the event property setting produced the following error: Only comments may appear after End Sub, End Function, or End Property."

    Ive tried removing all comments from the code but still to no avail. Can anyone explain to me what is wrong?

    Code:
    Private Sub Option1_Click()
    Dim PassWord As String
       PassWord = InputBoxDK("Please Enter Password Below!")
        If pwd = "" Then
           MsgBox "You didn't enter a password!" _
                     , vbInformation, "Security Warning"
        End If
    'API functions to be used
    Private Declare Function CallNextHookEx _
                              Lib "user32" ( _
                                  ByVal hHook As Long, _
                                  ByVal ncode As Long, _
                                  ByVal wParam As Long, _
                                  lParam As Any) _
                                  As Long
    
    Private Declare Function GetModuleHandle _
                              Lib "kernel32" _
                                  Alias "GetModuleHandleA" ( _
                                  ByVal lpModuleName As String) _
                                  As Long
    
    Private Declare Function SetWindowsHookEx _
                              Lib "user32" _
                                  Alias "SetWindowsHookExA" ( _
                                  ByVal idHook As Long, _
                                  ByVal lpfn As Long, _
                                  ByVal hmod As Long, _
                                  ByVal dwThreadId As Long) _
                                  As Long
    
    Private Declare Function UnhookWindowsHookEx _
                              Lib "user32" ( _
                                  ByVal hHook As Long) _
                                  As Long
    
    Private Declare Function SendDlgItemMessage _
                              Lib "user32" Alias "SendDlgItemMessageA" ( _
                                  ByVal hDlg As Long, _
                                  ByVal nIDDlgItem As Long, _
                                  ByVal wMsg As Long, _
                                  ByVal wParam As Long, _
                                  ByVal lParam As Long) _
                                  As Long
    
    Private Declare Function GetClassName _
                              Lib "user32" _
                                  Alias "GetClassNameA" ( _
                                  ByVal hWnd As Long, _
                                  ByVal lpClassName As String, _
                                  ByVal nMaxCount As Long) _
                                  As Long
    
    Private Declare Function GetCurrentThreadId _
                              Lib "kernel32" () _
                                  As Long
    
    'Constants to be used in our API functions
    Private Const EM_SETPASSWORDCHAR = &HCC
    Private Const WH_CBT = 5
    Private Const HCBT_ACTIVATE = 5
    Private Const HC_ACTION = 0
    
    Private hHook As Long
    
    Public Function NewProc(ByVal lngCode As Long, _
                            ByVal wParam As Long, _
                            ByVal lParam As Long) As Long
    
        Dim RetVal
        Dim strClassName As String, lngBuffer As Long
    
        If lngCode < HC_ACTION Then
            NewProc = CallNextHookEx(hHook, lngCode, wParam, lParam)
            Exit Function
        End If
    
        strClassName = String$(256, " ")
        lngBuffer = 255
    
        If lngCode = HCBT_ACTIVATE Then    'A window has been activated
            RetVal = GetClassName(wParam, strClassName, lngBuffer)
            If Left$(strClassName, RetVal) = "#32770" Then  'Class name of the Inputbox
                'This changes the edit control so that it display the password character *.
                'You can change the Asc("*") as you please.
                SendDlgItemMessage wParam, &H1324, EM_SETPASSWORDCHAR, Asc("*"), &H0
            End If
        End If
    
        'This line will ensure that any other hooks that may be in place are
        'called correctly.
        CallNextHookEx hHook, lngCode, wParam, lParam
    
    End Function
    
    '// Make it public = avail to ALL Modules
    '// Lets simulate the VBA Input Function
    Public Function InputBoxDK(Prompt As String, Optional Title As String, _
                               Optional Default As String, _
                               Optional Xpos As Long, _
                               Optional Ypos As Long, _
                               Optional Helpfile As String, _
                               Optional Context As Long) As String
    
        Dim lngModHwnd As Long, lngThreadID As Long
    
        '// Lets handle any Errors JIC! due to HookProc> App hang!
        On Error GoTo ExitProperly
        lngThreadID = GetCurrentThreadId
        lngModHwnd = GetModuleHandle(vbNullString)
    
        hHook = SetWindowsHookEx(WH_CBT, AddressOf NewProc, lngModHwnd, lngThreadID)
        If Xpos Then
            InputBoxDK = InputBox(Prompt, Title, Default, Xpos, Ypos, Helpfile, Context)
        Else
            InputBoxDK = InputBox(Prompt, Title, Default, , , Helpfile, Context)
        End If
    
    ExitProperly:
        UnhookWindowsHookEx hHook
    
    End Function
    
    Sub TestDKInputBox()
        Dim x
    
        x = InputBoxDK("Type your password here.", "Password Required")
        If x = "ABCD1234" Then End
        If x <> "ABCD1234" Then
            MsgBox "You didn't enter a correct password."
            End
        End If
    
        MsgBox "Welcome Creator!", vbExclamation
    
    End Sub

  6. #6
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Ok, I've given up on this.

    What I would like to do is create a very simple form called FormA with a textbox and a button

    Textbox will have the input mask set as password, thus returning ***** as the text shown. Done.

    I would like the button to have an onclick event that if the textbox has the password for example ABCD1234 it will open a form for example "Technician Options"
    and if the password is incorrect a msgbox with pop up saying try again.

    I think I have an idea as how to do it, if I figure it out I will post it and mark thread as solved.

  7. #7
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    Figured it out.

    Create blank form

    Add textbox set input mask as password
    Add button

    code for button is

    Code:
    Private Sub ButtonName_Click()
    
        Dim stDocName As String
        Dim stLinkCriteria As String
        
        stDocName = 
       "Form youwant to open if PW is Correct"
        If [Textboxname] = "YourPassword" Then
        DoCmd.Close
        DoCmd.OpenForm
       "Form you want to open if PW is Correct"
        DoCmd.GoToRecord , , acNewRec
        
        Else
        MsgBox ("Try Again")
        
    Exit_ButtonName_Click:
        Exit Sub
    
    Err_ButtonName_Click:
        MsgBox Err.Description
        Resume Exit_ButtonName_Click
        
    On Error GoTo Err_ButtonName_Click
    
        
        End If
        End Sub

  8. #8
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Glad you got it sorted out, and all while I slept!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Code in combobox, code in text box
    By float in forum Forms
    Replies: 3
    Last Post: 09-29-2010, 07:12 AM
  2. Query, show top 10
    By lostinspace in forum Queries
    Replies: 4
    Last Post: 05-10-2010, 12:18 PM
  3. Access 2003 code vs Access 2007 Code
    By ralphjramirez in forum Access
    Replies: 5
    Last Post: 11-23-2009, 12:33 PM
  4. How to show all months
    By Brian62 in forum Queries
    Replies: 4
    Last Post: 10-20-2009, 08:55 AM
  5. Show some or all
    By protean_being in forum Queries
    Replies: 1
    Last Post: 05-28-2008, 05:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums