-
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
-
[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]
-
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.
-
Thank you Norie,
the third one actually compiled but now I have it working.
-
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
-
Forum Rules