Public Variable

Stemdriller

Registered User.
Local time
Today, 21:50
Joined
May 29, 2008
Messages
187
Hi all

I am trying to define a Public Variable for the first time and having a few issues.

I have declared the variable as

Public AdminUser As String.

When the user logs in

AdminUser = Me.cbo_user.Column(1)

Doing a step into hovering the mouse over 'AdminUser' does indeed show the username.

But in different forms, if a button is invisible by default, if certain users log in certain buttons should be become visible
So on the form_current i am typing

If AdminUser = "John Smith" Then
Command1.Visible = True

I was then expecting the button to become visible, but it doesn't

Can someone put me right?

Thanks
 
frst, the public variable needs to be declared in a code module, not in the ofrms module

then -are you sure you haven't declared adminuser in more than one place - maybe as a control name on a form, or as a variable in a forms code module. put your mouse on adminuser in your code, and press shift-F2, and it will take you to the variable it is using.

to help prevent side effects like this, it is a good idea to add option explicit at the top of every code module.
 
Thanks for replying

I have now changed the Public Variable to ControlsAdmin, just to make sure AdminUser isn't elsewhere.

I have simply placed the Public ControlsAdmin as String, onto the first form?? I take it that's not the Code Module???

So I have created a separate Module file and placed the above variable in that as Explicit.

When it runs, the Button is still invisible, but if you go into the Design Mode of the form, close it down and then run again, the button does appear!!!!
 
Thanks for replying

I have now changed the Public Variable to ControlsAdmin, just to make sure AdminUser isn't elsewhere.

I have simply placed the Public ControlsAdmin as String, onto the first form?? I take it that's not the Code Module???

So I have created a separate Module file and placed the above variable in that as Explicit.

When it runs, the Button is still invisible, but if you go into the Design Mode of the form, close it down and then run again, the button does appear!!!!


Sorted it now, it needed code on the 'On Close' of the form.

Thanks again
 

Users who are viewing this thread

Back
Top Bottom