PDA

View Full Version : Solved: set User Names to an array



Djblois
04-30-2007, 08:46 AM
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:
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

try 2:

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

try 3:

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

they all install the menuobject no matter what the username is

Bob Phillips
04-30-2007, 09:18 AM
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

Norie
04-30-2007, 01:12 PM
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.

Djblois
04-30-2007, 01:14 PM
Thank you Norie,

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

Norie
04-30-2007, 01:22 PM
Are you sure it compiled?

When I pasted it into a module this line was highlighted in red.

If For Each CurrentUser In Developer