User Authentication System for Access 2007 Questions

padlocked17

Registered User.
Local time
Today, 15:51
Joined
Aug 29, 2007
Messages
276
Alrighty -

After learning that 2007 has no User Security roles, and not having Sharepoint or a SQL server, I decided to work starting with Bob's Simple Login script located here.

I've got it functioning fine and incorporated some of the options also made available here.

You'll see the code below used to store info in a hidden form that is holding the username and permissions level. I'm looking to try and store this information into a global variable instead of a hidden table.

I know that I could define it as a variable right here in the code, but how do I define it as a Global variable so I can use it later in the application in the VBA?

Code:
Private Sub cmdLogin_Click()
Dim strUser As String
Dim strPWD As String
Dim intUSL As Integer

strUser = Me.txtUser
If DCount("[UserPWD]", "tblUsers", "[UserName]='" & Me.txtUser & "'") > 0 Then
    strPWD = DLookup("[UserPWD]", "tblUsers", "[UserName]='" & Me.txtUser & "'")
    If strPWD = Me.txtPwd Then
        intUSL = DLookup("[SecurityGroup]", "tblUsers", "[UserName]='" & Me.txtUser & "'")
[COLOR="Red"]        Forms!frmUSL.txtUN = strUser
        Forms!frmUSL.txtUSL = intUSL[/COLOR]
        Select Case intUSL
            Case 1
                DoCmd.OpenForm "frmHome", acNormal
            Case 2
                DoCmd.OpenForm "frmHome", acNormal, , , acFormReadOnly
            Case 3
                MsgBox "Not configured yet", vbExclamation, "Not configured"
            Case 4
                MsgBox "Not configured yet", vbExclamation, "Not configured"
        End Select
        DoCmd.Close acForm, "frmLogin", acSaveNo
    Else
        If MsgBox("You entered an incorrect password" & vbCrLf & _
            "Would you like to re-end your password?", vbQuestion + vbYesNo, "Restricted Access") = vbYes Then
            Me.txtPwd.Value = ""
            Counter = Counter + 1
                If Counter = DLookup("[OptionValueNum]", "tblOptions", "[OptionsID]=1") Then
                MsgBox "You have entered an incorrect password too many times. This database will now close!", vbCritical, "Wrong password!"
                DoCmd.Quit
                End If
        Else
            DoCmd.Quit
    End If
    End If
End If
End Sub
 
I would suggest using Pat Hartman's suggestion of using a hidden form for holding those values. I used to use global variables too, but there are times where they can get reset, so having a hidden form can actually make it easier and less prone to losing the values.
 
That does make sense, and I would hate for a user to log in, and for me to then lose the ability to specify what items they can actually perform in the DB.

Do you add additional values to use in that hidden form as opposed to using Global variables as well?
 
Just use however many unbound text boxes as needed to hold the "global variable." In otherwords, you aren't using global variables, but the text boxes in lieu of.
 
Awesome. I'll start putting that practice into action.

Thanks.
 

Users who are viewing this thread

Back
Top Bottom