Me.Command0.Visible = CurrentUser = "ManagerUserName"

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Lynn,

I tried the

Me.Command0.Visible = CurrentUser = "ManagerUserName"

and I'm having problems making it work.

Here is what I did:
1. Opened the switchboard in design view.
2. Opened the properties of the command button I wanted to change.
3. Under events, did the Event Procedure for On Click and inserted the
following:

Private Sub Option3_Click()
Me.Command0.Visible = CurrentUser = "Joe Leon"
End Sub

When I run and click on the command button, I get a Compile error:

Method or data member not found.

and the Me.Command0 is highlighted.

What am I doing wrong? Thanks... joe
 
1) > and add the following code to the Open event of your form
(not the Click event of the control you want to hide. It won't fire unless
the control is clicked).

2) substitute the name of the control you want to hide for Command0. In your
case, it seems you want
Me.Option3.Visible = CurrentUser = "ManagerUserName"

HTH,
 
I think your code is in the wrong place and I don't particulary care for the
coding style. Technically, the code is susposed to evaluate whether
CurrentUser = "Joe Leon" as a True or False statement. It is a little harder
for a human to read it.
The way I see it now, the button is visible until someone clicks on it. I
don't think that is what you really want.

I would start by making the button's visible property False in design mode,
then in the Form's Open event, make the code:

If CurrentUser = "Joe Leon" Then
Me.command0.visible = True
End If
 
Joe Leon said:
Hi Lynn,

I tried the

Me.Command0.Visible = CurrentUser = "ManagerUserName"

and I'm having problems making it work.

Here is what I did:
1. Opened the switchboard in design view.
2. Opened the properties of the command button I wanted to change.
3. Under events, did the Event Procedure for On Click and inserted the
following:

Private Sub Option3_Click()
Me.Command0.Visible = CurrentUser = "Joe Leon"
End Sub

When I run and click on the command button, I get a Compile error:

Method or data member not found.

and the Me.Command0 is highlighted.

What am I doing wrong? Thanks... joe

In Lynn's posted code, "Command0" was just a stand-in for the actual
name of the command button you want to hide. So if "Command0" isn't
actually the name of a control on your form, Access won't recognize it
as a "method or data member", and you'll get that message.

Is "Option3" the name of the button you want to hide? As others have
said, it doesn't make a lot of sense to do it in the button's Click
event. Lynn suggested doing it in the form's Open event. And you won't
be able to hide the button in its own Click event anyway, because for
that event to be firing, the control must have the focus, and you can't
hide a control that has the focus.
 
Folks,
Thank you all for your help. Sorry It's taken me this long to check the
replies.

Yes, the name of the button is Option3 but it's not a form I'm trying to
open. It's a report. I opened the report properties and under OPEN I did the
event procedure. The code I placed in it was Me.Option3.Visible = Current
User = "Joe Leon"

Do I need an IF and End IF staement somewhere? I keep getting the "method
or data member not found" error.

Here is what the code looks like:

Private Sub Report_Open(Cancel As Integer)
Me.Option3.Visible = CurrentUser = "Joe Leon"
End Sub





What am I doing wrong?
 
Joe Leon said:
Folks,
Thank you all for your help. Sorry It's taken me this long to check
the replies.

Yes, the name of the button is Option3 but it's not a form I'm trying
to open. It's a report. I opened the report properties and under
OPEN I did the event procedure. The code I placed in it was
Me.Option3.Visible = Current User = "Joe Leon"

Do I need an IF and End IF staement somewhere? I keep getting the
"method or data member not found" error.

Here is what the code looks like:

Private Sub Report_Open(Cancel As Integer)
Me.Option3.Visible = CurrentUser = "Joe Leon"
End Sub


What am I doing wrong?

When you say "Me.Option3" in the code for the report, you're referring
to a control named "Option3" on *the report*. Didn't you say the
Option3 control is on the form? "Me" always refers to the object
containing the code that is running.

I'm not sure moving this code to the report makes sense. What are you
actually trying to do? Your first message in this thread started in the
middle of things, with a reply to a message from Lynn Trapp from some
other thread, so I don't really know what you're trying to achieve.
Please step back and explain the setup and what you want to have happen
under what circumstances.
 
Dirk,

Thanks for your response. Yes, let me start from the begining.

I have a switchboard with 4 buttons. One opens up a form that is used by all
the employees to enter their status.

The other three buttons are used to open up reports.

Button #3 is used so that only the manager can open a report that displays
all the employees status. This is button that I referred to. Originally,
Lynn suggested to use CurrentUser as a filter. This is where it all began.
Your help is very much welcomed. THANKS !
Joe...
 
Joe Leon said:
Dirk,

Thanks for your response. Yes, let me start from the begining.

I have a switchboard with 4 buttons. One opens up a form that is used
by all the employees to enter their status.

The other three buttons are used to open up reports.

Button #3 is used so that only the manager can open a report that
displays all the employees status. This is button that I referred to.
Originally, Lynn suggested to use CurrentUser as a filter. This is
where it all began. Your help is very much welcomed. THANKS !

So the idea, as I understand it, is that this button should only be
visible if the current user is the manager. Is that right? Is
"Option3" the name of the button? Is this switchboard form one that was
created by the built-in Swtichboard Manager, or is basically just an
unbound form with some command buttons on it?

I hope you've been made aware that the CurrentUser function is only
useful if user-level security has been applied to the database, so that
users have to log in with their user ID and password whenever they open
the database. Has that been done?

If you answer all these questions, I expect we can come up with a
solution in short order.
 
Dirk,

Yes, I implemented user-level security and tested it.
The switchboard was created using the Switchboard Manager.
Yes, button 3 should only be visible when the CurrentUser is the manager.
The name of the button is Option3

Thanks!
Joe..
 
Joe Leon said:
Dirk,

Yes, I implemented user-level security and tested it.
The switchboard was created using the Switchboard Manager.
Yes, button 3 should only be visible when the CurrentUser is the
manager. The name of the button is Option3

Then you should be able to achieve what you want by adding the following
line to the form's Open event:

Me.Option3.Visible = (CurrentUser() = "Joe Leon")

(assuming that "Joe Leon" is the username of the manager).

I expect that there will be other code in the form's Open event. In a
test switchboard I created, there is this code in the Open event:

'----- start of original code -----
Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.

' Move to the switchboard page that is marked as the default.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.FilterOn = True

End Sub
'----- end of original code -----

You would change this by adding the line I mentioned, so that it looks
like this:

'----- start of revised code -----
Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.

' Move to the switchboard page that is marked as the default.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.FilterOn = True

Me.Option3.Visible = (CurrentUser() = "Joe Leon")

End Sub
'----- end of revised code -----

That ought to do it. You can expect this to leave a gap where the
Option3 button would go. If you want to avoid that, you'll need to
modify the query that returns the switchboard items, rather than
modifying the Visible property of the button.
 
Dirk, Thanks!

You refer to the form's Open event:

I'm confused.. What form are you refering to? Thanks! Joe...

Dirk Goldgar said:
Joe Leon said:
Dirk,

Yes, I implemented user-level security and tested it.
The switchboard was created using the Switchboard Manager.
Yes, button 3 should only be visible when the CurrentUser is the
manager. The name of the button is Option3

Then you should be able to achieve what you want by adding the following
line to the form's Open event:

Me.Option3.Visible = (CurrentUser() = "Joe Leon")

(assuming that "Joe Leon" is the username of the manager).

I expect that there will be other code in the form's Open event. In a
test switchboard I created, there is this code in the Open event:

'----- start of original code -----
Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.

' Move to the switchboard page that is marked as the default.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.FilterOn = True

End Sub
'----- end of original code -----

You would change this by adding the line I mentioned, so that it looks
like this:

'----- start of revised code -----
Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.

' Move to the switchboard page that is marked as the default.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.FilterOn = True

Me.Option3.Visible = (CurrentUser() = "Joe Leon")

End Sub
'----- end of revised code -----

That ought to do it. You can expect this to leave a gap where the
Option3 button would go. If you want to avoid that, you'll need to
modify the query that returns the switchboard items, rather than
modifying the Visible property of the button.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Dirk,

I wasn't thinking of the Switchboard as a form... Sorry... It took me a
while to figure it out.

Thanks! I'm going to make the changes and let you know how it goes...

Joe...
 
Joe Leon said:
Dirk,

I wasn't thinking of the Switchboard as a form... Sorry... It took me
a while to figure it out.

Yes, that's the form I mean.
Thanks! I'm going to make the changes and let you know how it
goes...

Good luck! It ought to work -- it worked for me in a test.
 
Dirk,

Thanks for all the help !!

I tried doing a new posting and it's not working. Hope you get to see this
message.

Here is what I'm trying to do.

The switchboard opens on startup, but I would like only the switchboard to
be displayed so that the objects, tables, etc... are not availabe for viewing.

Also, when the switchboard is closed either through the X or a close button,
I would like to Exit Access completely.

Thanks!
Joe...
 
Joe Leon said:
Dirk,

Thanks for all the help !!

I tried doing a new posting and it's not working. Hope you get to see
this message.

What was the problem?
Here is what I'm trying to do.

The switchboard opens on startup, but I would like only the
switchboard to
be displayed so that the objects, tables, etc... are not availabe for
viewing.

This is done by setting one of the database's Startup options. Click
Tools -> Startup..., and uncheck the box "Display Database Window".
Also, when the switchboard is closed either through the X or a close
button, I would like to Exit Access completely.

Create an event procedure for the Switchboard form's Close event, like
this:

'----- start of code -----
Private Sub Form_Close()

Application.Quit

End Sub
'----- end of code -----
 
Back
Top