Private Sub 登录_Click()
On Error GoTo er
Dim conn As ADODB.Connection, rs As ADODB.Recordset
Set conn = CurrentProject.Connection
Set rs = New ADODB.Recordset
Dim userName As Variant
Dim userPass As Variant
userName = Trim(Nz(Text1, ""))
userPass = Trim(Nz(Text3, ""))
If userName = "" Or userPass = "" Then '判断用户名和密码是否为空
MsgBox "用户名和密码不能为空,请重新输入!", vbOKOnly + vblnformation, "错误信息"
GoTo noTrue
Else
rs.Open "select * from 职工信息 where 用户名='" & Text1 & "'", conn
If rs.RecordCount < 1 Then
MsgBox "用户不存在,请重新输入", vbOKOnly + vbInformation, "错误信息 "
GoTo noTrue
Else
If userPass <> rs!密码 Then '判断密码是否正确
MsgBox "密码不正确,请重新输入", vbOKOnly + vbInformation, "错误信息 "
GoTo noTrue
Else
'将登录时间计入数据库
CurrentDb.Execute "insert into 用户登录记录表(用户名,登录时间) values('" & userName & "',#" & Now() & "#,)"
DoCmd.Close
DoCmd.OpenForm "日志录入"
End If
End If
rs.Close
End If
Exit Sub
noTrue:
Text1 = ""
Text3 = ""
Text1.SetFocus
Exit Sub
er:
MsgBox "发生错误:" & Err.Number & "," & Err.Number
End Sub