Is there an easy way to Hide/Unhide Control Buttons on a Tab Page of a Form

MSAccessRookie

AWF VIP
Local time
Today, 15:48
Joined
May 2, 2008
Messages
3,428
Hello All,

I have been assigned to convert an existing MA Access 2003 Database to run using SQL Server 2005. As my Nickname might imply, I am still learning to use MS Access. I have spent time looking in this forum and believe that I will be able to find some answers here.

Background:

The Financial group, the Production Group, and the Research Group of the company each currently have their own Front End with additional special features that are only available to them. As a result, changing one of the common features requires updating and testing three separate templates. I would like to combine them all into a single templates in (for support purposes), and would like each of the groups to only have access to the special features that they presently have access to. For testing purposes, I have created a Special Features Tab that contains all of the special features.

Question:

Is there an easy way to Hide/Unhide Control Buttons on a Tab Page of a Form (or even a whole Tab Page if necessary) based on the User ID of the person running Access at the time? We already have the username on the form (determined via the function fOSUserName())

Thanks in advance for all who are able to provide suggestions or answers.
 
Sure. In the load event of the form you can test the user and hide/show the appropriate controls. You can use If/Then or Select/Case. What part are you having trouble with?
 
Pbaldy,

Since MS Access and Visual Basic are not my Primary Forte (yet), I was unaware of how Forms were loaded and what control I had over the process. Any suggestions as to where I might study up on this?
 
You have the user name; how do you determine what group they're in? How many controls are we talking about roughly (on the rest of the form that will always be visible, and on the special tab that are conditionally visible)? Those answers will guide us to the best way to solve the problem.
 
Pbaldy,

As a short term fix, there are 3 individuals (one from each group) whose IDs will be used to access the special features. We could also add the other users if required. This would work because the number of total users in each group is still very small. The company is willing to accept the single user solution for now, but in the longer term, we will have to assign users to groups or determine a way to assign "group rights" to the special features and the user base.

I just needed to know how to create the conditional access and/or display for the buttons
 
REPOST OF ABOVE FOR CLARIFICATION:

At this point, we have no way to determine what group the users are in by their ID alone. As a short term fix, there are 3 individuals (one from each group) whose IDs will be used to access the special features. We could also add the other users if required. This would work because the number of total users in each group is still very small. The company is willing to accept the single user solution for now, but in the longer term, we will have to assign users to groups or determine a way to assign "group rights" to the special features and the user base.

The number of controls is Limited (at this time), To One or two per group (no more than five controls in all). These could be placed on a single tab (or on separate tabs if that is easier) and access could be granted as required.

The default status of the controls (or tabs) should be INVISIBLE, and they should be come VISIBLE only to authorized users.

I just needed to know how to create the conditional access and/or display for the buttons.

I hope this provides the information you requested.
 
Well, at its simplest:

Code:
If Me.UserGroup = "Research" Then
  Me.ResearchButton.Visible = True
ElseIf Me.UserGroup = "Production" Then
  Me.ProductionButton.Visible = True
End If

Substituting with the names of your controls of course. Depending on various things, I might use Select/Case instead of If/Then, or I might even use a loop of all the controls on the form, using the Tag property to determine when to make each visible. Maybe that gets you started and then as your needs get more refined, we'll tweak the method.

Welcome to the site by the way.
 
Pbaldy,

Please forgive my apparent ignorance of the issues, but while I thank you for your excellent assistance so far, and I am sure that I can modify the code to meet my needs, I am not sure that I know how to activate the code you provided.
 
We're all ignorant of the issues until we learn about them. Forgive me for not giving you everything you needed, and don't be afraid to ask questions.

Get your form into design view, and open up its properties. On the Events tab, click anywhere in the row titled "On Load". Click on the ellipsis (...) to the right. If offered 3 choices, choose Code builder. You should be in the Visual Basic editor, and it should have created 2 lines:

Code:
Private Sub Form_Load()

End Sub

Between those 2 lines, paste the code I posted earlier, changing the names as appropriate. The nice thing about using "Me." is that as soon as you type the dot, you should be presented with a list of your controls (along with a lot of other stuff).
 
Pbaldy,

This is EXACTLY what I was hoping I would find. As a matter of record, your solution works with either option, (Hide a Control Button or Hide a Tab), so the management has both choices available for them. Thanks for your assistance, and I hope that one day I will be able to pay it forward and return the favor to another new user who has a problem that I can assist with.
 
No problem, and as I said feel free to post back if you get stuck.
 
I just noticed an issue with a Sub-Form not being aware of the value from the Form that contains it.

I defined a control called UserName in the top level Form WorkOrders, and all of the appropriate actions discussed previously work without issue. However, when I try to access the control from a Sub-Form called InvoiceDetails, It cannot locate the UserName Field because it is not a part of the local "me." Sub Group.

I tried to use the Macro Syntax Forms!WorkOrders!UserName to identify the field and received a "Run-time error '438': Object Doesn't support this property or method" error message, so this was not the solution. My manuals and guidebooks do not seem to address the subject, and I cannot find any reference to it in this fourm.

Can I address the values from the WorkOrders form?
 
odin1701,

Thanks for the suggestion. It worked just the way that I wanted it to. I also discovered that me.parent.parent works for a third level sub form that I encountered.

The last issue that I have for now is regarding whether there is a way to make the UserName Control Field GLOBAL to all forms, or whether each of the Main Forms will need its own UserName Control Field. (Note: The Form WorkOrders always stays open if that helps any)
 
If that form is always open, you can always grab it from there. You can get it from elsewhere using the syntax from the link above:

Forms!FormName.ControlName
 

Users who are viewing this thread

Back
Top Bottom