Admin Button, Enter Password Only Once

Megaduck

Member
Local time
Today, 15:20
Joined
Apr 24, 2020
Messages
30
Hello,

I'm trying to figure out how I might modify the code I have so that admins only have to enter the password once per session instead of every time the button is clicked.

This is what I have:
Code:
Private Sub Adminbtn_Click()
Dim strPasswd

    strPasswd = InputBox("Enter Password", "Restricted Form")

    If strPasswd = "" Or strPasswd = Empty Then
        MsgBox "No Input Provided", vbInformation, "Required Data"
        Exit Sub
    End If

    If strPasswd = DLookup("[Admin Pass]", "[Password]") Then
        DoCmd.OpenForm "Admin Panel", acNormal
    Else
        MsgBox "Sorry, you do not have access to this form", _
               vbOKOnly, "Important Information"
        Exit Sub
    End If
End Sub

I'm assuming this would be done by setting a tempvar, but I'm not 100% sure how to go about that while still providing the input box if that variable isn't set.
 
Hi. It might start out something like:
Code:
If TempVars!AdminPwd & "" = "" Then
    TempVars.Add "AdminPwd", Inputbox(...)
Else
...
 
Hi. It might start out something like:
Code:
If TempVars!AdminPwd & "" = "" Then
    TempVars.Add "AdminPwd", Inputbox(...)
Else
...

Thanks! I'll give that a try.
 
This worked for what I was looking for, if anyone one else runs across this too:
Code:
Private Sub Adminbtn_Click()
    Dim strPasswd

    If IsNull(TempVars("AdminPwd")) Then
        strPasswd = InputBox("Enter Password", "Restricted Form")
    Else
        strPasswd = TempVars!AdminPwd
    End If

    If strPasswd = "" Or strPasswd = Empty Then
        MsgBox "No Input Provided", vbInformation, "Required Data"
        Exit Sub
    End If

    If strPasswd = DLookup("[Admin Pass]", "[Password]") Then
        TempVars.Add "AdminPwd", DLookup("[Admin Pass]", "[Password]")
        DoCmd.OpenForm "Admin Panel", acNormal
    Else
        MsgBox "Sorry, you do not have access to this form", _
               vbOKOnly, "Important Information"
        Exit Sub
    End If
End Sub

Thanks, @theDBguy for your help! I always overthink these things... really wasn't that complicated... lol!
 
Last edited:
This worked for what I was looking for, if anyone one else runs across this too:
Code:
Private Sub Adminbtn_Click()
    Dim strPasswd

    If IsNull(TempVars("AdminPwd")) Then
        strPasswd = InputBox("Enter Password", "Restricted Form")
    Else
        strPasswd = TempVars!AdminPwd
    End If

    If strPasswd = "" Or strPasswd = Empty Then
        MsgBox "No Input Provided", vbInformation, "Required Data"
        Exit Sub
    End If

    If strPasswd = DLookup("[Admin Pass]", "[Password]") Then
        TempVars.Add "AdminPwd", DLookup("[Admin Pass]", "[Password]")
        DoCmd.OpenForm "Admin Panel", acNormal
    Else
        MsgBox "Sorry, you do not have access to this form", _
               vbOKOnly, "Important Information"
        Exit Sub
    End If
End Sub

Thanks, @theDBguy for your help! I always overthink these things... really wasn't that complicated... lol!
You're welcome and congratulations on figuring it out. Good luck with your project.
 

Users who are viewing this thread

Back
Top Bottom