You didn't specify what errors you are getting.... did you single step through the code to see where the error(s) were?
For help on debugging, see http://www.cpearson.com/Excel/DebuggingVBA.aspx
I always specify which library I using, especially in A2007. You need to set a reference to "Microsoft DAO 3.6 Object Library". (IIRC, in A2007 the default library is ADO.)
The IF() function has two forms, the single line form or the block form. Inside the do loop, you combined the two - cannot do that.
"Form_frmLogin.txtUsername" is how Access refers to a form. If the code is in the form module, you should use "Me.frmLogin.txtUsername" or "Forms!frmLogin.txtUsername".
If the code is in a standard module, you would have to use "Forms!frmLogin.txtUsername".
You do not have to add ".Value", since "Value" is the default property. It doesn't hurt, but it is not necessary.
Added clean up stuff.
My changes are in blue:
Code:
Private Sub cmdlogin_Click()
Dim dbs As DAO.Database
Dim rstUserPwd As DAO.Recordset
Dim bFoundMatch As Boolean
Set dbs = CurrentDb
bFoundMatch = False
Set rstUserPwd = dbs.OpenRecordset("qryUserPwd")
If rstUserPwd.RecordCount > 0 Then
rstUserPwd.MoveFirst
Do While rstUserPwd.EOF = False
If rstUserPwd![UserName] = Me.txtUsername And rstUserPwd![Password] = Me.TxtPassword Then
bFoundMatch = True
Exit Do
End If
rstUserPwd.MoveNext
Loop
End If
If bFoundMatch = True Then
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "frmSwitchboard"
Else
'
MsgBox "Incorrect Username or Password"
End If
'clean up
rstUserPwd.Close
Set rstUserPwd = Nothing
Set dbs = Nothing
End Sub
PS I have not executed (tested) the code, just reviewed it.