Password Protection Switchboard Option

Hi all:

I'm working to modify the switchboard logic to add a password function to an Admin option off of the main switchboard. These are the tricks: #1) I must use the switchboard and the switchboard manager; #2) the password, while entered, must not be shown (input mask = password); and #3) the code must integrate into the existing switchboard code and function with the switchboard manager.

The only way I know to satisfy trick #2 is to use a form. If it wasn't for that, this would be easy.

The idea is when a user clicks on the Admin button on the main switchboard a password form (Switchboard Access Form) would open prompting the user for the password. When a password is entered and the user clicks the OK button on the password form, the password form hide itself and the switchboard code validates the password. If valid, the switchboard logic continues by showing the Admin switchboard. If invalid, the user is given an error message with Yes or No buttons to continue. If the user clicks the Yes button, the switboard code would then go back to the password validation logic.

This is the code and the problem. The switchboard does not wait for the password to be entered (password form is a modal popup), it continue on its way while the password form hangs in the wings.

INFORMATIONAL: [Switchboard Access Form]![CmdButtonClick] is a text field on the password form that stores the value 1 if the OK button is clicked and 2 if the Cancel button is clicked.


Const Pass0 = 0              ' Default
Const Pass1 = 1              ' Password Test Passed
Const Pass2 = 2              ' Msgbox NO to continue
Const Pass3 = 3              ' Cancel Button

Dim Result As Integer
Dim PassResult As Integer

PassResult = Pass0

If Me("Optionlabel" & intBtn).Caption = "&Admin. Switchboard" Then
   DoCmd.OpenForm "Switchboard Access Form"
   While PassResult = Pass0
      If Forms![Switchboard Access Form]![CmdButtonClick] = 1 Then
         If Forms![Switchboard Access Form]![TxtPassword] <> "Today" Then
             Result = MsgBox("Invalid password. Do you want to try again?", _
                      vbYesNo + vbCritical, "Access Denied")
             Select Case Result
               Case vbYes
                 Forms![Switchboard Access Form].Visible = True
               Case vbNo
                 PassResult = Pass2
             End Select
           PassResult = Pass1
           DoCmd.Close "Switchboard Access Form"
         End If
          PassResult = Pass3
          DoCmd.Close "Switchboard Access Form"
       End If
End If

If PassResult = Pass2 Or _
   PassResult = Pass3 Then
      Exit Function
End If
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you might achieve the desired behavior by setting the password form's "Modal" property to yes.

but in general, you can create a modal form (i.e., a form that prevents the user from switching back to other forms while it is displayed) like this:

1. Create a new module

2. In this module, declare a private variable that can hold the return value, e.g.,
      Private ReturnValueOfThisFunction As String

3. Write a public sub that sets the return value to the parameter of the sub, e.g.,
      Public Sub SetReturnValue(ByVal s As String)
        ReturnValueOfThisFunction = s
      End Sub

4. Design the dialog box as a regular form whith the properties set as follows:
      Pop Up = Yes
      Modal = Yes
      Border Style = Dialog

5. For any command button that closes the form, set an event that calls the sub created in step 2 and hand it the desired parameter, e.g.,
      SetReturnValue (Me.txtInput)

6. Still in the same module created in step 1, write the desired public function (the one you would like to call later by your code), including the initialization of the private variable, the modal opening of the dialog box form, and the setting of the return value, e.g.,
      Public Function MyFunction() As String
        ReturnValueOfThisFunction = "(emtpy)"
        DoCmd.OpenForm "frmDialogBox", acNormal, , , , acDialog
        MyFunction = ReturnValueOfThisFunction
      End Function

using this method, you can call your password form with a public function and catch its return value, then continue with the code accordingly.  while the password dialog is shown, the user will not be able to switch to the switchboard form.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stevensontAuthor Commented:
It works. Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.