Originally Posted by
Derrick T. Davidson
I followed the tutorial from XIPooo on creating a classic Log in form, below is the code I wrote:
Option Compare Database
Option Explicit
Private Sub btnLogin_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("LogIn_tbl", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "UserName='" & Me.txtUserName & "'"
If rs.NoMatch = True Then
Me.lblwronguser.Visible = True
Me.txtUserName.SetFocus
Exit Sub
End If
Me.lblwronguser.Visible = False
If rs!Password <> Me.txtPassword Then
Me.lblwrongpassword.Visible = True
Me.txtPassword.SetFocus
Exit Sub
End If
Me.lblwrongpassword.Visible = False
DoCmd.Close acForm, "LogIn_frm"
DoCmd.OpenForm "Home_frm"
End Sub
The problem I have when I enter a wrong user name it works fine, however when I hit enter or click the Log In Button after entering the correct user name it skips the password entry and closes the form without a password. The tutorial was shown for 2013 I am running 2010 is there a difference in programming?
Or I have I coded the second part of the routine wrong???
You might want to have a look at the sample code I posted for the login.
https://drive.google.com/folderview?...UtXRmJ1VS1yQUU
Here's the code from that sample code:
Code:
Private Sub btnLogin_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tbl1Employees", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "UserName='" & Me.txtUserName & "'"
If rs.NoMatch Then
Me.lblWrongUser.Visible = True
Me.txtUserName.SetFocus
Exit Sub
End If
Me.lblWrongUser.Visible = False
If rs!Password <> Me.txtPassword Then
Me.lblWrongPass.Visible = True
Me.txtPassword.SetFocus
Exit Sub
End If
Me.lblWrongPass.Visible = False
DoCmd.OpenForm "frmMain"
DoCmd.Close acForm, Me.Name
End Sub
It looks like you are closing the form before opening the new form. Closing the form will cause the code to stop at that point.