E
Eric
Hello everyone.
I am having some issues with my Login Form. It works great
but there is one problem that has me stumped. I have a
table setup called tblSecurity that has different security
levels set to it. I know that this isn't the best way to
do security, but it is a simple database. The fields are:
ID(num), Password(num), EmpName, and Access Level
which is a lookup to tblSecurity which has:
Access Level, Description, and AccessLevelID (number).
In my form, I have the following code:
Private Sub cmdLogin_Click()
Dim MyEmpID As Long, ACode As Long
'From http://www.microsoft-accesssolutions.co.uk/login.htm
Run "AccessCheck", ACode <-- this is giving me headaches!
'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
("Password", "tblUser", "[ID]=" & Me.cboEmployee.Value)
Then
MyEmpID = Me.cboEmployee.Value
DoCmd.OpenForm "frmChangePassword", acDesign, , ,
acFormEdit, acWindowNormal
DoCmd.Close acForm, "frmPassword", acSaveNo
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 admin.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
The AccessCheck code is this(in a module):
Sub AccessCheck(ACode As Integer, UserID)
ACode = DLookup("AccessLevelID", "tblUser", "ID = " &
ID)
End Sub
What I want to do validate that the user has access to the
database then figure out his access level. Any ideas? The
AccessCheck is not working correctly.
Eric
I am having some issues with my Login Form. It works great
but there is one problem that has me stumped. I have a
table setup called tblSecurity that has different security
levels set to it. I know that this isn't the best way to
do security, but it is a simple database. The fields are:
ID(num), Password(num), EmpName, and Access Level
which is a lookup to tblSecurity which has:
Access Level, Description, and AccessLevelID (number).
In my form, I have the following code:
Private Sub cmdLogin_Click()
Dim MyEmpID As Long, ACode As Long
'From http://www.microsoft-accesssolutions.co.uk/login.htm
Run "AccessCheck", ACode <-- this is giving me headaches!
'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
("Password", "tblUser", "[ID]=" & Me.cboEmployee.Value)
Then
MyEmpID = Me.cboEmployee.Value
DoCmd.OpenForm "frmChangePassword", acDesign, , ,
acFormEdit, acWindowNormal
DoCmd.Close acForm, "frmPassword", acSaveNo
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 admin.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
The AccessCheck code is this(in a module):
Sub AccessCheck(ACode As Integer, UserID)
ACode = DLookup("AccessLevelID", "tblUser", "ID = " &
ID)
End Sub
What I want to do validate that the user has access to the
database then figure out his access level. Any ideas? The
AccessCheck is not working correctly.
Eric