Environ("Username")

TallMan

Registered User.
Local time
Today, 02:02
Joined
Dec 5, 2008
Messages
239
Good Afternoon all,

I think I have an easy one here but I am unable to get anything to work.

I am trying to creat a form that when it opens, if it is not the supervisors certain buttons are not visible.

Please see my code below. Sford is me and I can not get the buttons to show when I open the form, let alone when I add all of the other supervisors names.

Any ideas?

PHP:
Private Sub Form_Load()
If Environ("username") <> "Sford" Then
''''''Or Environ("username")
'''''''<> "supname" Or Environ("username") <> "supname" Or Environ("username") <> "supname" Or Environ("username") <> "supname" Then
    Me.missingemail.Visible = False
    Me.pendingemail.Visible = False
    Me.Command43.Visible = False
    Me.Client_Letter_Mail_Merge.Visible = False
    Me.Command67.Visible = False
    Me.Command68.Visible = False
    Me.Label80.Visible = False
    Me.Box81.Visible = False
    Me.Box74.Visible = False
    Me.Label75.Visible = False
        Else
             Me.missingemail.Visible = True
             Me.pendingemail.Visible = True
             Me.Command43.Visible = True
             Me.Client_Letter_Mail_Merge.Visible = True
             Me.Command67.Visible = True
             Me.Command68.Visible = True
             Me.Label80.Visible = True
             Me.Box81.Visible = True
             Me.Box74.Visible = True
             Me.Label75.Visible = True
    End If
End Sub
 
1. Create a table for your supervisor names. That way you don't have to change code if supervisors leave or come.

2. To save on code, put a tag in those controls which only the supervisors can have (perhaps just sup)

3. Then you can do this:

Code:
Dim ctl As Control
Dim intSup As Integer

intSup = DCount("*", "tblYourSupervisorTable", "SupervisorID = " & Chr(34) & VBA.Environ("Username") & Chr(34))

For Each ctl In Me.Controls
    If ctl.Tag = "sup" Then
       ctl.Visible = intSup
    End If
Next ctl
 
Last edited:
just add another button

with

msgbox(environ("username"))

to see what you really have. It should be the domain login name for the user.
 
Hey Bob.

You lost me on step two. Where do I place the "Tag"? I am unfamiliar with that term.

Thanks for all of your help.
 
Hey Bob.

You lost me on step two. Where do I place the "Tag"? I am unfamiliar with that term.

Thanks for all of your help.

Open your form in design view, click on a control and then in the properties, go to the OTHER tab. It is the last item listed. Type in those three letters

sup

and do that for every control you want only the supervisor to have access to.
 
WOW...I learn something everyday! Great Tip!!! Cheers.
 

Users who are viewing this thread

Back
Top Bottom