I am trying to write a code for the login. I have took into account
of the all the possibilities and therefore came with the following
code:
Private Sub cmdLogin_Click()
Dim db As Database
Dim rs As Recordset
Set db = OpenDatabase(App.Path & "\login.mdb")
Set rs = db.OpenRecordset("login")
Do While Not rs.EOF
If rs.Fields("username") <> (txtUsername.Text) And _
rs.Fields("password") <> (txtPassword.Text) Then
MsgBox "Incorrect username and password!", vbCritical
ElseIf rs.Fields("username") <> (txtUsername.Text) Then
MsgBox "Incorrect username!", vbCritical
ElseIf rs.Fields("password") <> (txtPassword.Text) Then
MsgBox "Incorrect password!", vbCritical
ElseIf txtUsername.Text = "" And txtPassword.Text = "" Then
MsgBox "Empty fields!", vbCritical
ElseIf txtPassword.Text = "" Then
MsgBox "Empty password!", vbCritical
ElseIf txtUsername.Text = "" Then
MsgBox "Empty username!", vbCritical
ElseIf rs.Fields("username") = (txtUsername.Text) And _
rs.Fields("password") = (txtPassword.Text) Then
quizFrm.Show
Unload Me
Exit Sub
Else
rs.MoveNext
End If
Loop
End Sub
However, it does not read the second record after the first. For
example if I enter a username which is the second record of the
database, it says "Incorrect username!". Can anyone suggest me an
improvement to the above code?
much appreciated