Hello,
I have login form for filling "UserID(primary key) and password" and also I have table "tblPASSWORD". I don't know why this doesn't work. When I filling the UserID and password then click the button, I got error "Item can not be found in the collection correspond to the requested name or ordinal". But I can find this UserID and password in the table that means I enter the correct UserID and password.
May be the UserID duplicate when I enter it? if so, how to solve it.
Many Thanks.
Jeannia
The following are my codes:
Private Sub Command6_Click()
On Error GoTo Err_Command6_Click
Dim conn As New ADODB.Connection
Dim com As New ADODB.Command
Set conn = CurrentProject.Connection
Set com.ActiveConnection = conn
Dim rst As ADODB.Recordset
Dim strSQL As String
Dim sPasswd$
strSQL = "select UserID, Password from tblPASSWORD " & _
"where UserID like '" & txtUserID & "'"
Set rst = New ADODB.Recordset
rst.Open strSQL, conn
If rst.EOF And rst.BOF Then
MsgBox "No such userID (" & txtUserID & "
. Please try again.", vbInformation, "Unkown user"
GoTo Exit_Command6_Click
Else
sPasswd = rst.Fields(2) & ""
If sPasswd <> Me.txtPassWord Then
MsgBox "Incorrect userid and/or password.", vbInformation, "Authentication failed"
GoTo Exit_Command6_Click
End If
End If
DoCmd.OpenForm "frmInspectors"
Exit_Command6_Click:
' clean up and then exit
rst.Close
conn.Close
Set rst = Nothing
Set conn = Nothing
Exit Sub
Err_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_Click
End Sub
I have login form for filling "UserID(primary key) and password" and also I have table "tblPASSWORD". I don't know why this doesn't work. When I filling the UserID and password then click the button, I got error "Item can not be found in the collection correspond to the requested name or ordinal". But I can find this UserID and password in the table that means I enter the correct UserID and password.
May be the UserID duplicate when I enter it? if so, how to solve it.
Many Thanks.
Jeannia
The following are my codes:
Private Sub Command6_Click()
On Error GoTo Err_Command6_Click
Dim conn As New ADODB.Connection
Dim com As New ADODB.Command
Set conn = CurrentProject.Connection
Set com.ActiveConnection = conn
Dim rst As ADODB.Recordset
Dim strSQL As String
Dim sPasswd$
strSQL = "select UserID, Password from tblPASSWORD " & _
"where UserID like '" & txtUserID & "'"
Set rst = New ADODB.Recordset
rst.Open strSQL, conn
If rst.EOF And rst.BOF Then
MsgBox "No such userID (" & txtUserID & "
GoTo Exit_Command6_Click
Else
sPasswd = rst.Fields(2) & ""
If sPasswd <> Me.txtPassWord Then
MsgBox "Incorrect userid and/or password.", vbInformation, "Authentication failed"
GoTo Exit_Command6_Click
End If
End If
DoCmd.OpenForm "frmInspectors"
Exit_Command6_Click:
' clean up and then exit
rst.Close
conn.Close
Set rst = Nothing
Set conn = Nothing
Exit Sub
Err_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_Click
End Sub