我有一個登錄屏幕,用於控制對主導航窗體中按鈕的訪問。我希望用戶安全級別確定哪些按鈕是可見的。我的問題是,如果我嘗試添加多個button.visible = False,那麼表單會中斷,除了我試圖隱藏的頂部按鈕外,我會看到其他所有按鈕。我在編碼VBA方面很新穎(上週我基本上只是買了一本書),而我是hopihn,我只是缺少一些簡單的東西。誰能幫忙?代碼如下。使用多個button.visible = False訪問VBA
Private Sub Command1_Click()
Dim User As String
Dim UserLevel As Integer
Dim TempPass As String
Dim ID As Integer
Dim workerName As String
Dim TempLoginID As String
Dim SecLevel As String
If IsNull(Me.txtUserName) Then
MsgBox "Please enter UserName", vbInformation, "Please Enter your HealthcareID this is the same Id you use to log into windows"
Me.txtUserName.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please enter Pin Number", vbInformation, "Please enter your Pin Number"
Me.txtPassword.SetFocus
Else
If IsNull(DLookup("UserLogin", "tblUser", "UserLogin = '" & Me.txtUserName.Value & "' And password = '" & Me.txtPassword.Value & "'")) Then
MsgBox "Invalid UserName or Password! Use your HealthcareID as your username and your pin code to access."
Else
TempLoginID = Me.txtUserName.Value
workerName = DLookup("[UserName]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
UserSecurity = DLookup("[UserSecurity]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
TempPass = DLookup("[password]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
Unit = DLookup("[Unit]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
Unit = DLookup("[Unit]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
DoCmd.Close
Select Case UserSecurity
Case Is = 1 'Admins
DoCmd.OpenForm "Navigation Form"
Forms![Navigation Form]![TxtUser] = workerName
Forms![Navigation Form]![txtName] = TempLoginID
Forms![Navigation Form]![txtUnit] = Unit
Forms![Navigation Form]![txtUserSecurity] = UserSecurity
' DoCmd.BrowseTo acBrowseToForm, "frmFirstPage", "Navigation Form.NavigationSubForm", , , acFormEdit
Case Is = 2 'Managers
DoCmd.OpenForm "Navigation Form"
Forms![Navigation Form]![TxtUser] = workerName
Forms![Navigation Form]![txtName] = TempLoginID
Forms![Navigation Form]![txtUnit] = Unit
Forms![Navigation Form]!AdminPageButton.Visible = False
Forms![Navigation Form]![txtUserSecurity] = UserSecurity
' DoCmd.BrowseTo acBrowseToForm, "frmFirstPage", "Navigation Form.NavigationSubForm", , , acFormEdit
Case Is = 3 'Coordinators
DoCmd.OpenForm "Navigation Form"
Forms![Navigation Form]![TxtUser] = workerName
Forms![Navigation Form]![txtName] = TempLoginID
Forms![Navigation Form]![txtUnit] = Unit
Forms![Navigation Form]![txtUserSecurity] = UserSecurity
Forms![Navigation Form]!btnManagersMenu.Visible = False
Forms![Navigation Form]!AdminPageButton.Visible = False
' DoCmd.BrowseTo acBrowseToForm, "frmFirstPage", "Navigation Form.NavigationSubForm", , , acFormEdit
Case Else 'RCRs
DoCmd.OpenForm "Navigation Form"
Forms![Navigation Form]![TxtUser] = workerName
Forms![Navigation Form]![txtName] = TempLoginID
Forms![Navigation Form]![txtUnit] = Unit
Forms![Navigation Form]![txtUserSecurity] = UserSecurity
Forms![Navigation Form]!AdminPageButton.Visible = False
Forms![Navigation Form]!btnManagersMenu.Visible = False
Forms![Navigation Form]!btnCoordMenu.Visible = False
' DoCmd.BrowseTo acBrowseToForm, "frmFirstPage", "Navigation Form.NavigationSubForm", , , acFormEdit
End Select
End If
End If
End Sub
根據你的回答,我能夠找到我在代碼中犯的一個錯字。謝謝! –
很高興我能幫忙! – JennyW