Results 1 to 2 of 2
  1. #1
    rosaj is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2011
    Posts
    7

    Password Protect button on Switchboard

    Hi,



    So I have a Main switchboard that has 5 buttons that all lead to more switchboards (all are created using the switchboard manager). There are 4 buttons that everyone in the company department needs to access and then there is an administrator button. I need to password protect the administrator button so that when the correct password is entered the Admin switchboard page opens. Right now I have a form called frmPassword and the action when the admin button is clicked opens frmPassword. There are two buttons on frmPassword, Enter and Cancel. The enter button has this on click event:

    Private Sub cmdShowAdminArea_Click()
    On Error GoTo ErrorPoint
    If Len(Nz(Me!txtPassword, "")) = 0 Then
    MsgBox "Please enter a password before continuing." _
    , vbCritical, "Missing Password"
    Me.txtPassword.SetFocus
    Else
    If Me.txtPassword <> "MyPassword" Then
    ' just an example password
    MsgBox "Incorrect Password", vbExclamation, "Access Denied"
    DoCmd.close acForm, "frmPassword"
    Else
    Forms!Switchboard.Filter = "[ItemNumber] = 0 And [SwitchboardID] = 7"
    Me.FilterOn = True
    Forms!Switchboard.Refresh
    DoCmd.close acForm, "frmPassword"
    End If
    End If
    ExitPoint:
    Exit Sub
    ErrorPoint:
    ' Unexpected Error
    MsgBox "The following error has occurred:" _
    & vbNewLine & "Error Number: " & Err.Number _
    & vbNewLine & "Error Description: " & Err.Description _
    , vbExclamation, "Unexpected Error"
    Resume ExitPoint
    End Sub

    When Access goes through the code it basically just passes over the part highlighted in red because it doesn't go to that page. In the Switchboard Table the admin switchboard and the buttons on it are denoted by:

    SwitchboardID ItemNumber ItemText Command Argument
    7 0 Administrator 0
    7 1 Go Back 1 1
    7 2 Records 1 8
    7 3 Stand. 1 9
    7 4 Inst. 1 14
    7 5 Close 6

    So basically my problem is getting the Adminstrator switchboard page to open when the correct password is used because right now all the happends when the correct password is used is that frmPassword closes.

    Please help!!!

    Thanks!!!!!!!!!!!!!!!!!

  2. #2
    rosaj is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2011
    Posts
    7
    I figure it out using this link

    http://www.utteraccess.com/forum/vba...d#entry2040273

    The reason it wasn't working the other way is because Access 2007 uses macros to run everything in the Switchboard so you have to creat something called a temperary variable. I'll post both codes.

    my code ends up calling the function module from this link and it works perfectly. Just copy and paste these the first to the on click event of the button on your Password form (use this link to make the password form http://www.accessmvp.com/JConrad/acc...l#specificmenu) and the other you have to create a new module in the VB window and then just copy and paste. Follow the comments to change the switchboard page and password:

    Private Sub cmdShowAdminArea_Click()
    On Error GoTo ErrorPoint
    If Len(Nz(Me!txtPassword, "")) = 0 Then
    MsgBox "Please enter a password before continuing." _
    , vbCritical, "Missing Password"
    Me.txtPassword.SetFocus
    Else
    If Me.txtPassword <> "password" Then
    ' Substitute with your own password between the quotes
    MsgBox "Incorrect Password", vbExclamation, "Access Denied"
    DoCmd.close acForm, "frmPassword"
    Else
    OpenProtectedSwitchboard (txtPassword)
    DoCmd.close acForm, "frmPassword"
    End If
    End If
    ExitPoint:
    Exit Sub
    ErrorPoint:
    ' Unexpected Error
    MsgBox "The following error has occurred:" _
    & vbNewLine & "Error Number: " & Err.Number _
    & vbNewLine & "Error Description: " & Err.Description _
    , vbExclamation, "Unexpected Error"
    Resume ExitPoint
    End Sub

    this is the function module

    Option Compare Database
    Option Explicit
    Public Function OpenProtectedSwitchboard(pass As String)
    On Error GoTo ErrorPoint
    ' Prompt for a password
    If pass = "password" Then
    ' Create a TempVar for the SwitchboardID equal to 7 for the seventh menu
    ' **Important** Adjust number to match the menu you want
    TempVars.Add "SwitchboardID", 7
    ' Requery the form to refresh the commands shown using new menu
    Forms!Switchboard.Requery
    ' Finally, make the the two label controls in the header section match the switchboard name
    ' Remove these if you don't have those two controls in the header
    Forms!Switchboard!Label1.Caption = DLookup("ItemText", "Switchboard Items", "[SwitchboardID] = " & TempVars("SwitchboardID"))
    Forms!Switchboard!Label2.Caption = DLookup("ItemText", "Switchboard Items", "[SwitchboardID] = " & TempVars("SwitchboardID"))
    End If
    ExitPoint:
    Exit Function
    ErrorPoint:
    MsgBox "The following error has occurred:" _
    & vbNewLine & "Error Number: " & Err.Number _
    & vbNewLine & "Error Description: " _
    & Err.Description, vbExclamation, _
    "Unexpected Error"
    Resume ExitPoint
    End Function

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

Similar Threads

  1. Password protect a form
    By recon2011 in forum Forms
    Replies: 10
    Last Post: 11-18-2012, 04:36 PM
  2. Password Protect Buttons on Forms
    By Desstro in forum Forms
    Replies: 13
    Last Post: 08-24-2012, 05:04 PM
  3. Password Protect Forms
    By jlclark4 in forum Security
    Replies: 3
    Last Post: 01-25-2011, 04:26 PM
  4. readonly password protect
    By mlgehle in forum Security
    Replies: 1
    Last Post: 03-13-2010, 08:59 PM
  5. Password Protect Forms
    By Robert M in forum Programming
    Replies: 3
    Last Post: 01-15-2010, 01:50 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 - Senior Forums