How to program command button in Access Macro to require a password

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cambar
    New Member
    • Jul 2010
    • 20

    How to program command button in Access Macro to require a password

    I created a simple macro to open a form with several command buttons on the form. On one of these buttons I want to require a password for access. I am not a programmer. What do I need to do to make this happen?

    Thanks for your help
  • Rixxe
    New Member
    • Oct 2010
    • 7

    #2
    You really should google in the first instance, as many of the answers you want are avaliable.

    None the less:

    Open the switchboard form in design view and select the command button.
    Select the On Click event and choose Event Procedure from the drop down list. Click on the ellipses (...) to enter the code window.

    Code:
    Private Sub cmdOpenEmpForm_Click()
    
    'Attached to On Click event of cmdOpenEmpForm
    
        Dim strPasswd
    
        strPasswd = InputBox("Enter Password", "Restricted Form")
    
        'Check to see if there is any entry made to input box, or if
        'cancel button is pressed. If no entry made then exit sub.
    
        If strPasswd = "" Or strPasswd = Empty Then
            MsgBox "No Input Provided", vbInformation, "Required Data"
            Exit Sub
        End If
    
        'If correct password is entered open Employees form
        'If incorrect password entered give message and exit sub
    
        If strPasswd = "Graham" Then
            DoCmd.OpenForm "frmEmp", acNormal
        Else
            MsgBox "Sorry, you do not have access to this form", _
                   vbOKOnly, "Important Information"
            Exit Sub
        End If
    End Sub
    You will notice the line If strPasswd = "Graham" Then . This contains the required password that will be required when attempting to open the form.

    This can be changed to any password that you wish.


    (Note: This information is originally from, and can be found at: http://www.databasedev.co.uk/button_security.html)

    Comment

    • cambar
      New Member
      • Jul 2010
      • 20

      #3
      Thanks very much. Worked great.

      Comment

      • Rixxe
        New Member
        • Oct 2010
        • 7

        #4
        You're welcome.

        Comment

        Working...