[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 890
  • Last Modified:

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
1 Solution
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.

stevensontAuthor Commented:
It works. Thanks!

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now