Password Protection Switchboard Option

Posted on 2004-11-07
Last Modified: 2012-05-05
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
Question by:stevensont
    LVL 14

    Accepted 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.


    Author Comment

    It works. Thanks!

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Suggested Solutions

    When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now