Having trouble with a recordset for Login screen
I'm setting up a login screen for an Access app I'm developing, that checks the user's Employee ID and Password against the database. However, when I run the code I get the following error:
"Item cannot be found in the collection corresponding to the requested name or ordinal."
I know what this error means, but the fields I am looking up are the exact ones that are in the database (EmployeeID and Password).
Here is the exact code:
Function Login(EmployeeID As String, Password As String) As Boolean
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.Open DbConnectionString
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
With rs
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.Open "SELECT FirstName, LastName, AccessCode FROM tblEmployees WHERE EmployeeID='" & EmployeeID & "'", conn
End With
If rs.BOF And rs.EOF Then
Exit Function
End If
If EmployeeID = rs!EmployeeID And Password = rs!Password Then
intAccessCode = rs!AccessCode
strFirstName = rs!FirstName
strLastName = rs!LastName
Login = True
Else
Login = False
End If
End Function
The line that's being flagged as the error is "If EmployeeID = rs!EmployeeID And Password = rs!Password Then"; with the debugger saying that the item cannot be found in the collection.
My table, tblEmployees, has the following fields:
EmployeeID - Text (Primary Key)
Password - Text
FirstName - Text
LastName - Text
AccessCode - Number
Any ideas on what's causing this problem?? I'm totally at a loss since the database fields exactly match the fields I'm trying to look up from the recordset
|