Insert access level - admin/user to login code (1 Viewer)

deanvilar

Registered User.
Local time
Yesterday, 17:01
Joined
Mar 27, 2013
Messages
63
Gurus, I found this wonderful login codes and I think its very cool...but 1 thing! I can't define USER LEVEL ACCESS after DLOOKUP .... can you share your ideas?

thank you...

Private Sub cmdLogin_Click()

'Check to see if data is entered into the UserName combo box

If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If

'Check to see if data is entered into the password box

If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If

'Check value of password in tblEmployees to see if this matches value chosen in combo box

If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then
lngMyEmpID = Me.cboEmployee.Value
'Close logon form and open splash screen

DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "ARCHIVE MENU FORM"

Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If

'If User Enters incorrect password 3 times database will shutdown

intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If

End Sub
 

Attachments

  • LOGIN.jpg
    LOGIN.jpg
    98.8 KB · Views: 113

jdraw

Super Moderator
Staff member
Local time
Yesterday, 20:01
Joined
Jan 23, 2006
Messages
15,385
From a quick glance, it appears you may have a misspelling. Are these really separate things?

[lngEmpID]=" & Me.cboEmployee.Value) Then
lngMyEmpID = Me.cboEmployee.Value
 

deanvilar

Registered User.
Local time
Yesterday, 17:01
Joined
Mar 27, 2013
Messages
63
oh I think its misspelled, anyway ... I tried the following codes instead of following that DLOOKUP thing ... but if you can give some solution for it ... it'll be nice bro

***what I did

Set db = CurrentDb
Set rst = db.OpenRecordset("tblEmployees", dbOpenTable)

rst.Index = "Primarykey"
rst.Seek "=", Me.cboEmployee

If rst.strEmpName = Me.cboEmployee And rst.strEmpPassword = Me.txtPassword And rst.strAccess = "ADMIN" Then

DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "ARCHIVE MENU FORM"
Forms![ARCHIVE MENU FORM]![cmdAddUser].Enabled = True
ElseIf rst.strEmpName = Me.cboEmployee And rst.strEmpPassword = Me.txtPassword And rst.strAccess = "USER" Then

DoCmd.Close acForm, "frmLogon", acSaveNo
DoCmd.OpenForm "ARCHIVE MENU FORM"
Forms![ARCHIVE MENU FORM]![cmdAddUser].Enabled = False
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If
rst.Close
 

Users who are viewing this thread

Top Bottom