Security Code

pastorkc

Board Regular
Joined
Jan 29, 2020
Messages
125
Office Version
  1. 2010
Platform
  1. Windows
I have set my code on my logon button, it keeps telling me that the Security Level has not been defined as a variable.

VBA Code:
Private Sub LogonBtn_Click()
     Dim ID As Long, PW As String, SL As String
    
    ID = Nz(DLookup("UserID", "UserT", "Username=""" & Username & """"), 0)
    If ID = 0 Then
        MsgBox "User not found"
        Quit
    End If
    
    PW = Nz(DLookup("Password", "UserT", "UserID=" & ID), "")
    If PW <> Password Then
        MsgBox "Incorrect Password"
        Quit
    End If
    
    SL = Nz(DLookup("SecurityLevel", "UserT", "UserID=" & ID), "")
    If SL <> SecurityLevel Then
        MsgBox "Access Denied"
        Quit
    End If
    
    TempVars("SecurityLevel") = SecurityLevel.Value
    DoCmd.OpenForm "MainMenuF"
    DoCmd.Close acForm, Me.Name, acSaveYes
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Not sure why that would be. :(
I would ask however why the security level is not numeric?
If none found, you are making it a ZLS ?
Also are we talking about SL or SecurityLevel ?
 
Upvote 0
Probably this.
TempVars("SecurityLevel") = SecurityLevel.Value

should be
TempVars("SecurityLevel") = SL

I would always prefix my controls with Me.
 
Upvote 0
it keeps telling me that the Security Level has not been defined as a variable.
Are you making up your own versions of error messages? I interpret the problem to be that you are using Option Explicit and you have an undeclared variable "username".
"Username=""" & Username & """"), 0)

As I see it, nz is returning a 0 if not found?
 
Upvote 0
Ya I think need to stop and rethink I what I am doing. To many interruptions Thank you everyone.
 
Upvote 0

Forum statistics

Threads
1,224,532
Messages
6,179,388
Members
452,908
Latest member
MTDelphis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top