求教:想要用access2010创建一个验证验证的宏,怎么实现不同用户有对应的登陆密码?
1个回答
展开全部
先建一张user表,对应不同的密码
然后点击按钮的时候执行以下的宏就可以实现了
Dim yhm As Variant
Dim mm As Variant
Dim db As Database
Dim rs As DAO.Recordset
yhm = Me.Text4.Value
mm = Me.Text6.Value
If IsEmpty(yhm) Or IsNull(yhm) Then
MsgBox "用户名不能为空", vbCritical
Exit Sub
ElseIf IsEmpty(mm) Or IsNull(mm) Then
MsgBox "密码不能为空", vbCritical
Exit Sub
End If
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM 用户角色表 where 用户名=" & Chr(39) & yhm & Chr(39) & " and 密码=" & Chr(39) & mm & Chr(39))
If rs.RecordCount > 0 Then
MsgBox "恭喜你,登录成功!", vbInformation
Me.Visible = False
Else
MsgBox "用户名或者密码不匹配!", vbCritical
End If
然后点击按钮的时候执行以下的宏就可以实现了
Dim yhm As Variant
Dim mm As Variant
Dim db As Database
Dim rs As DAO.Recordset
yhm = Me.Text4.Value
mm = Me.Text6.Value
If IsEmpty(yhm) Or IsNull(yhm) Then
MsgBox "用户名不能为空", vbCritical
Exit Sub
ElseIf IsEmpty(mm) Or IsNull(mm) Then
MsgBox "密码不能为空", vbCritical
Exit Sub
End If
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM 用户角色表 where 用户名=" & Chr(39) & yhm & Chr(39) & " and 密码=" & Chr(39) & mm & Chr(39))
If rs.RecordCount > 0 Then
MsgBox "恭喜你,登录成功!", vbInformation
Me.Visible = False
Else
MsgBox "用户名或者密码不匹配!", vbCritical
End If
追问
不懂
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询