访问表单简单VBA密码,3次尝试代码
我试图在Access中打开一个允许3次尝试的报告之前输入简单的密码,然后关闭表单。这是我想到的,但我在整理上有点困难,非常感谢您的帮助 谢谢访问表单简单VBA密码,3次尝试代码,vba,Vba,我试图在Access中打开一个允许3次尝试的报告之前输入简单的密码,然后关闭表单。这是我想到的,但我在整理上有点困难,非常感谢您的帮助 谢谢 Option Compare Database 'after clicking the button, the user must have the password to open the Report Private Sub btnOpenPayrollReport_Click() 'I need this to be the password
Option Compare Database
'after clicking the button, the user must have the password to open the Report
Private Sub btnOpenPayrollReport_Click()
'I need this to be the password
Dim password As String
password = "coke"
If InputBox("Please enter password to continue.", "Enter Password") <> password Then
DoCmd.OpenReport "Payroll", acViewReport, "", "", acNormal
Exit Sub
Else
'I need to allow the user 3 attempts before closing the form
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
DoCmd.Close
End If
End Sub
选项比较数据库
'单击按钮后,用户必须具有打开报告的密码
私有子btnOpenPayrollReport_Click()
'我需要这个作为密码
将密码设置为字符串
密码=“可口可乐”
如果输入框(“请输入密码以继续。”,“输入密码”),则输入密码
DoCmd.OpenReport“工资单”,acViewReport,“,”,acNormal
出口接头
其他的
'在关闭表单之前,我需要允许用户尝试3次
IntLogonatTests=IntLogonatTests+1
如果INTLOGONATTENTS>3,则
文件关闭
如果结束
端接头
我喜欢使用循环执行此操作:
Private Sub btnOpenPayrollReport_Click()
'I need this to be the password
Dim i As Integer
Dim password As String
password = "coke"
For i = 1 To 3
If InputBox("Please enter password to continue.", "Enter Password") = password Then
DoCmd.OpenReport "Payroll", acViewReport, "", "", acNormal
Exit Sub
Else
MsgBox "The password is incorrect. You have " & 3 - i & " Attemps", vbExclamation & vbOK
End If
'I need to allow the user 3 attempts before closing the form
Next i
DoCmd.Close
End Sub
这样,如果它到达循环的末尾,它就会关闭。这会在下次尝试时自动弹出
如果希望原始按钮作为启动器,则使用置于模块顶部代码外部的公共变量,使用以下命令:
Public intLogonAttempts As Integer
Private Sub btnOpenPayrollReport_Click()
'I need this to be the password
Dim password As String
password = "coke"
If InputBox("Please enter password to continue.", "Enter Password") = password Then
DoCmd.OpenReport "Payroll", acViewReport, "", "", acNormal
Exit Sub
Else
MsgBox "The password is incorrect. You have " & 3 - i & " Attemps", vbExclamation & vbOK
End If
'I need to allow the user 3 attempts before closing the form
If intLogonAttempts >= 3 Then DoCmd.Close
intLogonAttempts = intLogonAttempts + 1
End Sub
大家好,欢迎光临。你能解释一下你有什么具体的错误或问题吗?嗨,这个程序似乎不是这样工作的…基本上我只需要输入一个密码->然后如果它是正确的打开报告。如果没有,那就尝试一下,在3次错误的尝试后说“错误的传球”->关闭表单谢谢斯科特,这正是我想要做的。“我也要用文本框试试。”茨维汉德很高兴我能帮上忙。