Admin Button, Enter Password Only Once (1 Viewer)

Megaduck

Member
Local time
Today, 05:37
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.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:37
Joined
Oct 29, 2018
Messages
21,357
Hi. It might start out something like:
Code:
If TempVars!AdminPwd & "" = "" Then
    TempVars.Add "AdminPwd", Inputbox(...)
Else
...
 

Megaduck

Member
Local time
Today, 05:37
Joined
Apr 24, 2020
Messages
30
Hi. It might start out something like:
Code:
If TempVars!AdminPwd & "" = "" Then
    TempVars.Add "AdminPwd", Inputbox(...)
Else
...

Thanks! I'll give that a try.
 

Megaduck

Member
Local time
Today, 05:37
Joined
Apr 24, 2020
Messages
30
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:

theDBguy

I’m here to help
Staff member
Local time
Today, 02:37
Joined
Oct 29, 2018
Messages
21,357
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

Top Bottom