Consulting

Results 1 to 5 of 5

Thread: Solved: set User Names to an array

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Solved: set User Names to an array

    I have been using an individuals user name to choose which modules they get. However, the way I do it now I am doing an if statement for each users name. I want to change this process to make it easier when new people are hired. I am trying to group them by department and then do an if per department. This is what I have tried:

    try 1:
    [VBA]Dim Developer As Variant
    Dim CurrentUser As Variant
    Developer = Array("Dblois")

    If Environ("username") = Developer Then
    Set menuItem = menuObject.Controls.Add(Type:=msoControlButton)
    menuItem.OnAction = "QuickSalesPersonOrderForm"
    menuItem.Caption = "SalesPerson Order Form"
    end if[/VBA]

    try 2:

    [VBA]Dim Developer As Variant
    Dim CurrentUser As Variant
    CurrentUser = Environ("username")
    Developer = Array("Dblois")

    If CurrentUser = Developer Then
    Set menuItem = menuObject.Controls.Add(Type:=msoControlButton)
    menuItem.OnAction = "QuickSalesPersonOrderForm"
    menuItem.Caption = "SalesPerson Order Form"
    end if[/VBA]

    try 3:

    [VBA]Dim Developer As Variant
    Dim CurrentUser As Variant
    CurrentUser = Environ("username")
    Developer = Array("Dblois")

    If for each CurrentUser in Developer
    Set menuItem = menuObject.Controls.Add(Type:=msoControlButton)
    menuItem.OnAction = "QuickSalesPersonOrderForm"
    menuItem.Caption = "SalesPerson Order Form"
    next[/VBA]

    they all install the menuobject no matter what the username is

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim Developer As Variant
    Dim CurrentUser As Variant
    Developer = Array("Dblois")

    If Not IsError(Application.Match(Environ("username"), Developer, 0)) Then
    Set MenuItem = menuObject.Controls.Add(Type:=msoControlButton)
    MenuItem.OnAction = "QuickSalesPersonOrderForm"
    MenuItem.Caption = "SalesPerson Order Form"
    End If
    [/vba]

  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Djblois

    None of the code you posted looks right.

    In fact I would be amazed if the 3rd try even compiled.

    In the first 2 examples you appear to be forgetting you are using an array.

  4. #4
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Thank you Norie,

    the third one actually compiled but now I have it working.

  5. #5
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Are you sure it compiled?

    When I pasted it into a module this line was highlighted in red.
    [vba]
    If For Each CurrentUser In Developer
    [/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •