如何设置限制访问中的消息框的次数将显示
我已经在访问数据库中添加了登录表单。我正在尝试找出一种限制用户输入不正确密码的次数的方法。在下面显示的VBA代码中,当用户输入一个不正确的密码时,以下消息框触发了“ msgbox”不正确的密码”,vbokonly + vbexclamation。
我希望用户在出现其他消息框之前进行三次失败的尝试。类似“请联系管理员” ...
提前感谢您的帮助。
Private Sub OkBTN_Click()
'Check that User is selected
If IsNull(Me.cboUser) Then
MsgBox "You forgot to select your name from the drop down menu!", vbCritical
Me.cboUser.SetFocus
Else
'Check for correct password
If Me.txtPassword = Me.cboUser.Column(2) Then
'Check if password needs to be reset
If Me.cboUser.Column(4) Then
DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
End If
Me.Visible = False
Else
MsgBox "Incorrect password", vbOKOnly + vbExclamation
Me.txtPassword = Null
Me.txtPassword.SetFocus
End If
End If
End Sub
I have added a login form to an Access Database. I am trying to figure out a way to limit the number of times a user can enter an incorrect password. In the VBA code shown below, when the user inputs a password that is incorrect, the following message box triggers, "MsgBox "Incorrect password", vbOKOnly + vbExclamation".
I would like the user to get three failed attempts before a different message box appears. Something like, "Please contact administrator"...
Thanks in advance for the help.
Private Sub OkBTN_Click()
'Check that User is selected
If IsNull(Me.cboUser) Then
MsgBox "You forgot to select your name from the drop down menu!", vbCritical
Me.cboUser.SetFocus
Else
'Check for correct password
If Me.txtPassword = Me.cboUser.Column(2) Then
'Check if password needs to be reset
If Me.cboUser.Column(4) Then
DoCmd.OpenForm "frmPasswordChange", , , "[UserID] = " & Me.cboUser
End If
Me.Visible = False
Else
MsgBox "Incorrect password", vbOKOnly + vbExclamation
Me.txtPassword = Null
Me.txtPassword.SetFocus
End If
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这种情况下,我认为我会声明
static
计数器变量。静态变量的值在过程调用之间保留。其他替代方法是将计数存储在AA全局变量中,使用TeenPVAR或将其写入表。In this situation I think I'd declare a
Static
counter variable. The value of a static variable is preserved between procedure calls. Other alternatives would be to store the count in a a global variable, use a TempVar, or write them to a table.好的,谢谢本。我进行了一些更改,现在遇到了错误,“编译错误:没有if”。我想我已经失去了秩序,但是很难把它拿回来。
Okay thank you Ben . I have made some changes and am now getting error, "Compile error: Else without if". I think I got things out of order, but am having a tough time getting it back.