How do I Disable or Dim Sub-Menu Items Based on UserName

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aaitaman Tamang
    New Member
    • Jul 2011
    • 22

    How do I Disable or Dim Sub-Menu Items Based on UserName

    I have my own menu bar which i have created called "Angola LNG Incident Reporting". My intention was to dim or disable sub-menu items base on user name.

    Following code i am using right now. It works just fine to dim but doesn't appears to be working base one user's name. Is there any thing wrong of doing this.
    Code:
    If Me.UserName.Value = "aman" Then
        CommandBars("Angola LNG Incident Reporting").Controls(1).Controls(1).Enabled = False
        CommandBars("Angola LNG Incident Reporting").Controls(1).Controls(2).Enabled = False
        CommandBars("Angola LNG Incident Reporting").Controls(1).Controls(3).Enabled = False
    ElseIf Me.UserName.Value = "McAnthony" Then
        CommandBars("Angola LNG Incident Reporting").Controls(1).Controls(1).Enabled = True
        CommandBars("Angola LNG Incident Reporting").Controls(1).Controls(2).Enabled = True
        CommandBars("Angola LNG Incident Reporting").Controls(1).Controls(3).Enabled = True
    End If
    Appreciate if you help me out
    Thanks,

    ** Edit **
    This question was split away from How i can stop users running MDB file from another location?.
    Last edited by NeoPa; Oct 29 '11, 02:40 PM. Reason: Split and updated
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    Assuming the criterion is simply that it matches the term "aman", and that your object reference is correct, then your code should look like :
    Code:
    Dim blnShow As Boolean
    
    blnShow = Nz(StrComp(Me.UserName, "aman", vbTextCompare), True) = False
    With CommandBars("Angola LNG Incident Reporting").Controls(1)
        .Controls(1).Enabled = blnShow
        .Controls(2).Enabled = blnShow
        .Controls(3).Enabled = blnShow
    End With

    Comment

    Working...