For a long time, we've had no issue with this, but we've been getting this error a few times now, and I'm not sure what's going on.
Just in case, I checked my table:
Here's the segments of code I use for this:
Just in case, I checked my table:
Here's the segments of code I use for this:
Code:
Option Compare Database
'Username used for updating several forms
Public GUserName As String
Code:
'Log into database with username and password
Private Sub cmd_login_Click()
Dim db As dao.Database
Dim rst As dao.Recordset
Dim strSQL As String
If Trim(Me.txt_username.Value & vbNullString) = vbNullString Then
MsgBox prompt:="Username should not be left blank.", buttons:=vbInformation, Title:="Username Required"
Me.txt_username.SetFocus
Exit Sub
End If
If Trim(Me.txt_password.Value & vbNullString) = vbNullString Then
MsgBox prompt:="Password should not be left blank.", buttons:=vbInformation, Title:="Password Required"
Me.txt_password.SetFocus
Exit Sub
End If
'query to check if login details are correct
'updated query to include UserName 10/13/2020
strSQL = "SELECT FirstName, LastName, UserName FROM tbl_login WHERE Username = """ & Me.txt_username.Value & """ AND Password = """ & Me.txt_password.Value & """"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
If rst.EOF Then
'MsgBox prompt:="Incorrect username/password. Try again.", buttons:=vbCritical, Title:="Login Error" --- commented out 10/13/2020
MsgBox prompt:="Incorrect username/password. Try again.", buttons:=vbCritical, Title:="Login Error" & "strSQL = " & strSQL 'added 10/13/2020
Me.txt_username.SetFocus
Else
'MsgBox prompt:="Hello, " & rst.Fields(0).Value & ".", buttons:=vbOKOnly, Title:="Login Successful" --- commented out 10/13/2020
GUserName = rst.Fields("UserName").Value 'added 10/13/2020
MsgBox prompt:="Hello, " & GUserName & ". .CurrentUser=." & CurrentUser(), buttons:=vbOKOnly, Title:="Login Successful" 'added 10/13/2020
DoCmd.Close acForm, "frm_login", acSaveYes
End If
Set db = Nothing
Set rst = Nothing
DoCmd.OpenForm "Main Menu"
End Sub