Login program issue (1 Viewer)

Access_Help

Registered User.
Local time
Today, 01:10
Joined
Feb 12, 2005
Messages
136
It appears that the script is looking at the first record in the table only as oppose to looping over all records, the first user in the table allows the login but the others don't. Can anyone see any obvious mistake?


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

If IsNull(Me.txtUserName) Or Me.txtUserName = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.txtUserName.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", "Teachers") And Me.txtUserName.Value = DLookup("Username", "Teachers") And DLookup("Level", "Teachers") = "Admin" Then



'Close logon form and open splash screen



DoCmd.OpenForm "COURSES"
DoCmd.OpenForm "Admin"
DoCmd.OpenForm "Session", , , "[Username] = """ & Me.txtUserName & """"
DoCmd.Close acForm, "Login", acSaveNo

ElseIf Me.txtPassword.Value = DLookup("Password", "Teachers") And Me.txtUserName.Value = DLookup("Username", "Teachers") And DLookup("Level", "Teachers") = "Teacher" Then



'Close logon form and open splash screen

DoCmd.Close acForm, "Login", acSaveNo
DoCmd.OpenForm "COURSES"
DoCmd.OpenForm "Session", , , "[Username] = """ & Me.txtUserName & """"
DoCmd.Close acForm, "Login", acSaveNo



Else
MsgBox "Invalid Login. Please check and Try Again", vbOKOnly, _
"Invalid Entry!"
Me.txtPassword.SetFocus
 

isladogs

MVP / VIP
Local time
Today, 08:10
Joined
Jan 14, 2017
Messages
18,186
Much of this is fairly standard code but there are errors
Just out of interest where did you get the code from as the first part is exactly the same (word for word) as one of my schools apps.

However it first goes wrong when you refer to tblEmployees but don't use it
Can you explain how these code lines are meant to work in your opinion?

Code:
If Me.txtPassword.Value = DLookup("Password", "Teachers") And Me.txtUserName.Value = DLookup("Username", "Teachers") And DLookup("Level", "Teachers") = "Admin" Then
...
ElseIf Me.txtPassword.Value = DLookup("Password", "Teachers") And Me.txtUserName.Value = DLookup("Username", "Teachers") And DLookup("Level", "Teachers") = "Teacher" Then

In my own app, I have a hidden textbox txtTeacherID and this line of code
Code:
 'Make sure the teacherID is set for the username entered
    Me.txtTeacherID = Nz(DLookup("TeacherID", "Teachers", "UserName = '" & Me.txtUserName & "'"), "")

Assuming a valid user name has been entered, code is then used to validate that the entered password matching the password for that teacher. Or rather, as the password is encrypted, the entered password matches a decrypted version of the stored password.

You might find it useful to look at this example app: https://www.access-programmers.co.uk/forums/showthread.php?t=193131
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 01:10
Joined
Oct 29, 2018
Messages
21,358
Hi. I think your code only works for the first user because your DLookups are missing a criteria argument.
 

Users who are viewing this thread

Top Bottom