Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Apr 2008
    Location
    Jacksonville, North Carolina, USA
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    command buttons (access 2003)

    Good Afternoon all How is everyone good I hope. Well my question today is can you put a password on a command button so that when the user clicks on it they have to put a password in to view that form or report. or is there a way to make this happen if you can't do it with a command button. Thank you all in advance for your help. Talk with you all later

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: command buttons (access 2003)

    The best way to secure an Access database in Access 2003 or before is to apply user-level security. Users will have to login to the database using a username and password, and this will determine what they are allowed to do. See WendellB's tutorial The Secrets of Security for an overview and useful links.

    If you prefer *not* to apply user-level security, you can use VBA code like the following:

    Private Sub cmdOpenForm_Click()
    Const strCorrectPassword = "TopSecret"
    Dim strPassword As String
    strPassword = InputBox("Enter the password for this form")
    If StrComp(strPassword, strCorrectPassword, vbBinaryCompare) = 0 Then
    ' Password OK
    DoCmd.OpenForm "frmTest"
    Else
    MsgBox "Retro me Satanas!", vbExclamation
    End If
    End Sub

    You could also create a table with the names of forms and reports and the corresponding passwords, and use that instead of a constant strCorrectPassword.

  3. #3
    Lounger
    Join Date
    Apr 2008
    Location
    Jacksonville, North Carolina, USA
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: command buttons (access 2003)

    is there an example of the creating a table with the names of forms and reports and the corresponding passwords, and use that instead of a constant strCorrectPassword. thank you

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: command buttons (access 2003)

    Let's say that you create a table tblPasswords like this:

    <table border=1><td align=center>FormOrReport</td><td align=center>Password</td><td valign=top>frmThis</td><td valign=top>Secret</td><td valign=top>frmThat</td><td valign=top>GuessWhat</td><td valign=top>rptOther</td><td valign=top>Dunno</td></table>
    Instead of Const strCorrectPassword = ... you'd use
    <code>
    Dim strCorrectPassword As String
    strCorrectPassword = DLookup("Password", "tblPasswords", "FormOrReport='frmThat'")
    </code>
    if you want to open the form frmThat, and similar for the others.

  5. #5
    Lounger
    Join Date
    Apr 2008
    Location
    Jacksonville, North Carolina, USA
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: command buttons (access 2003)

    Thanks Hans

Posting Permissions

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