2017-03-14 4 views
0

メインナビゲーションフォームのボタンへのアクセスを制御するために使用しているログイン画面があります。ユーザーのセキュリティレベルでどのボタンが表示されているかを判断したい。私の問題は、複数のbutton.visible = Falseを追加しようとするとフォームが壊れてしまい、見えないようにしようとしたトップボタンを見るだけです。私はVBAをコーディングするのにかなり新しい(私は基本的に先週、本を買った)、私はちょっと単純なものを見逃していると思う。誰も助けることができますか?コードは以下のとおりです。複数のボタンを使用してVBAにアクセスするbutton.visible = False

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 

答えて

0

あなたのナビゲーションフォームの設定を見ることなく、私はあなたがこのようにフォームを開くしているときに、なぜあなたのその後のボタンが表示されたまま、非常にわからないので、私は、自分自身にアクセスし、VBAするのは非常に新しいです。しかし、Select Case UserSecurityコードをナビゲーションフォームのForm_Loadサブに移動してみることもできます。Form_LoadとForm_Currentのサブフォームで私のフォームと似たようなことを行い、複数のコマンドボタンやテキストフィールドなどが表示されたり、ユーザのセキュリティレベルを含む基準。これは私が一つの形で使用したサブの一例である -

Private Sub Form_Current() 
On Error GoTo Form_Current_Err 

Me.txtOrderStatus.Requery 'refresh the order status 

'move the cursor to the end of the PO No field 
Me.txtPONo.SetFocus 
If Not IsNull(Me.txtPONo) Then 
Me.txtPONo.SelStart = Len(Me.txtPONo) 
End If 

'make the contract no and project description fields visible only when the PO is related to a contract 
If txtPOType.Value = "Contract" Then 
     Me.txtContractNo.Visible = True 
     Me.txtProjectDescription.Visible = True 
     Me.txtParentPO.Visible = False 
     Me.POTabs.Pages(6).Visible = False 
ElseIf Me.txtPOType.Value = "Call Off Order" Then 'make the parent po visible if this is a call off order 
     Me.txtContractNo.Visible = False 
     Me.txtProjectDescription.Visible = False 
     Me.txtParentPO.Visible = True 
     Me.POTabs.Pages(6).Visible = True 

Else 
     Me.txtContractNo.Visible = False 
     Me.txtProjectDescription.Visible = False 
     Me.txtParentPO.Visible = False 
     Me.POTabs.Pages(6).Visible = False 
End If 

'check if the order is cancelled and hide all action buttons 
If Me.OrderStatus = "Cancelled" Then 
Me.cmdEditPO.Visible = False 
Me.cmdCancelOrder.Visible = False 
Me.txtCancelledOrderFlag.Visible = True 
Me.AmendedOrderFlag.Visible = False 
Else 
Me.cmdEditPO.Visible = True 
Me.txtCancelledOrderFlag.Visible = False 

End If 

'check if this a revised order and hide the Amended Order comment and the PO Revisions subform if it isn't 
If txtPORevision > 0 Then 
    If Me.OrderStatus <> "Cancelled" Then 
    Me.AmendedOrderFlag.Visible = True 
    Me.PO_Revisions.Visible = True 
    Else 
    Me.AmendedOrderFlag.Visible = False 
    Me.PO_Revisions.Visible = True 
    End If 
Else 
    Me.AmendedOrderFlag.Visible = False 
    Me.PO_Revisions.Visible = False 
End If 

'check if the PO needs approval and the user is a PO Approver, 
' and make the approve/cancel buttons visible as appropriate 
If Me.OrderStatus = "For Approval" And _ 
    (DLookup("Role", "dbo_Employees", "EmployeeID = " & TempVars!EmpID) = "Administrator" _ 
    Or DLookup("Role", "dbo_Employees", "EmployeeID = " & TempVars!EmpID) = "Manager") Then 
    'show the Approve PO button, hide the Cancel button 
    Me.cmdApproveOrder.Visible = True 
    Me.cmdCancelOrder.Visible = False 
Else 
'hide the Approve button, show the Cancel button 
    Me.cmdApproveOrder.Visible = False 
    If Me.OrderStatus <> "Cancelled" Then 
    Me.cmdCancelOrder.Visible = True 
    End If 
End If 

'if the order hasn't been approved yet, or is cancelled, hide the email button 
If Me.OrderStatus = "New" Or Me.OrderStatus = "Raised" Or Me.OrderStatus = "For Approval" _ 
Or Me.OrderStatus = "Not Approved" Or Me.OrderStatus = "Cancelled" Then 
    Me.cmdEmailPO.Visible = False 
Else 
    Me.cmdEmailPO.Visible = True 
End If 

'amend the caption of the Revise order button if the order has not been sent yet 
If Me.OrderStatus = "New" Or Me.OrderStatus = "Raised" Then 
Me.cmdEditPO.Caption = "Revise/Send Order" 
Else 
Me.cmdEditPO.Caption = "Revise this Order" 
End If 

'check if a filter is applied and highlight the filter button if it is 
If Me.FilterOn = True Then 
Me.cmdApplyFilter.BackColor = vbYellow 
Else 
Me.cmdApplyFilter.BackThemeColorIndex = 4 
Me.cmdApplyFilter.BackShade = 40 
Me.cmdApplyFilter.Gradient = 12 
End If 

'refresh the subform 
DoCmd.Requery "PO Details" 

また、あなたがすべてのケースで同じ値にtxtUser、txtName、txtUnitとtxtUserSecurityを設定し、そうではなく、それらを複数回宣言しているように見えますこのように、ナビゲーションフォーム自体のコントロールのデフォルト値として設定することができます。 TempLoginIDをTempVarとして宣言すると、データベース全体で利用できるようになり、必要な場所に他のデータのdlookupを置くことができます。または、Userテーブルを含むようにフォームのデータを設定できます。 dlookupを使わずに直接アクセスすることができます。

ほんの少し助けてください!

+0

あなたの答えに基づいて、私は自分のコードで行ったタイプミスを見つけることができました。ありがとうございました! –

+0

私は助けることができてうれしい! – JennyW

関連する問題