Code to go to Switchboard after Password Check

whirlwindgirl

New member
Local time
Today, 10:33
Joined
Apr 13, 2011
Messages
4
I have a switchboard that has options that only certain people can access. I have the code for the password protection, and it works. What I want is to insert code to go to the Main Switchboard after the Wrong Password box pops up. I've tried to insert it in several places, and I can't get it to work. Any Ideas? See below:

If Me.SwitchboardID = 2 Then
Dim x As String
x = "Password1"
Dim y As String
y = InputBox("Please Enter a Valid Password", "Password required")
If x <> y Then
MsgBox "Wrong password", , "Invalid Password"
DoCmd.OpenForm "Switchboard", acNormal, , , acFormReadOnly
End If
End If

If Me.SwitchboardID = 3 Then
Dim x1 As String
x1 = "Password2"
Dim y1 As String
y1 = InputBox("Please Enter a Valid Password", "Password required")
If x1 <> y1 Then
MsgBox "Wrong password", , "Invalid Password"
End If
End If
If Me.SwitchboardID = 4 Then
Dim x2 As String
x2 = "Password3"
Dim y2 As String
y2 = InputBox("Please Enter a Valid Password", "Password required")
If x2 <> y2 Then
MsgBox "Wrong password", , "Invalid Password"
End If
End If
 
What doesn't work? I would expect it to be immediately after the wrong password message box. What form is this code in?
 
What I may be tempted to try is to put your code in a Public Module and then call the Sub from the buttons on the Switchboard in the usual way - Command 8.

With the sub maybe something like this

Code:
Public Sub mySwitchboardButton()

Application.Echo False    ' stops the screen refreshing so the Main Switchboard 'appears' to stay open
Docmd.close acform,"Switchboard"

Now run your Password code and depending on the response, open the appropriate Switchboard and refresh the screen.

Note - if the Switchboard has any Filter code on the Open Event, then you will have to comment it out.


Code:
Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.

    ' Move to the switchboard page that is marked as the default.
    'Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
    'Me.FilterOn = True
    '
End Sub



Code:
Docmd.Openform "SwitchBoard",,,"[SwitchBoardID] = 1"
Application.Echo True

Obviously the SwitchboardID must be a control on the Swtichboard but you can always make it invisible.
 

Users who are viewing this thread

Back
Top Bottom