简单的登录窗体,老是提示密码和用户名错,高手给看看啊.....谢谢
Option Compare DatabaseDim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command_登录_Click()
Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset
rs.Open "用户表", cn
Dim userName As String
Dim userPass As String
Text__用户名.SetFocus
userName = Me!Text__用户名.Text
Text__密码.SetFocus
userPass = Me!Text__密码.Text
If Len(Nz(userName)) = 0 Or Len(Nz(userPass)) = 0 Then
MsgBox "用户名和密码不能为空,请重新输入……", vbOKOnly + vbInformation, "错误信息"
Text__用户名.SetFocus
Text__用户名.Text = ""
Text__密码.SetFocus
Text__密码.Text = ""
Text__用户名.SetFocus
Else
If userName <> rs!用户名 Or userPass <> rs!密码 Then
MsgBox "用户名和密码不正确,请重新输入……", vbOKOnly + vbInformation, "错误信息"
Text__用户名.SetFocus
Text__用户名.Text = ""
Text__密码.SetFocus
Text__密码.Text = ""
Text__用户名.SetFocus
Else
rs.Close
rs.Open "用户登录记录表", cn, adOpenDynamic, adLockBatchOptimistic
rs.AddNew
rs!用户名 = userName
rs!登录时间 = Now()
rs!退出时间 = CDate(0)
rs.Update
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
DoCmd.Close
DoCmd.OpenForm "焊接螺旋立铣刀价格总查询总窗体"
End If
End If
End Sub