在表单加载事件上,我检查了用户的访问级别。如果它低于某个阈值或者他们从未登录过,那么我就有了
行Cancel = true
但是,无论如何都会加载表单。这是整个表单加载事件。
Private Sub Form_Load()
If IsNull(Forms!frmUsernamePassword!txtUserName) Then
MsgBox "You need to enter a username or password first.", vbOKOnly + vbExclamation
Cancel = -1
ElseIf DLookup("[AccessLevel_ID]", "tblUsernamePasswords", "[txtUserName]= '" & Forms!frmUsernamePassword!txtUserName & "'") = 1 Then
MsgBox "Your Security Level is 1", vbOKOnly
ElseIf DLookup("[AccessLevel_ID]", "tblUsernamePasswords", "[txtUserName]= '" & Forms!frmUsernamePassword!txtUserName & "'") = 2 Then
MsgBox "Your Security Level is 2", vbOKOnly
ElseIf DLookup("[AccessLevel_ID]", "tblUsernamePasswords", "[txtUserName]= '" & Forms!frmUsernamePassword!txtUserName & "'") = 3 Then
MsgBox "Your Security Level is 3", vbOKOnly
ElseIf DLookup("[AccessLevel_ID]", "tblUsernamePasswords", "[txtUserName]='" Forms!frmUsernamePassword!txtUserName & "'") = 4 Then
MsgBox "Your Security Level is 4", vbOKOnly
End If
End Sub
抱歉格式化问题。
答案 0 :(得分:3)
表单加载没有取消参数。使用表格打开取消。设置控件的内容必须在表单加载中进行。