Visible/invisible control based on user access?

pholt33

Registered User.
Local time
Today, 14:03
Joined
Dec 3, 2013
Messages
15
Solved: Visible/invisible control based on user access?

My company has a new database that we will use to track PTO (paid time off/vacation), including the submission/approval process. Not everyone should have access to the approval dashboard as that should be restricted to only managers. Everyone will have the same basic form so that they can see their PTO history, hours remaining to be used, etc.

What I want to do is have a button on the form that is visible only if the person is a manager. The button will open the PTO approval form. How can I make a button visible/invisible based on user access levels?

Thanks!
 
Last edited:
you need to have a login table for each users name, password, etc. This should also include a field or fields indicating their access rights.

So in the form open event you would have a bit of code which would look up the user in this table (you would either have a global variable populated when the user logs in or you can use environ to determine the current windows login) and set the button's visible property depending on the access rights of the user
 
My company has a new database that we will use to track PTO (paid time off/vacation), including the submission/approval process. Not everyone should have access to the approval dashboard as that should be restricted to only managers. Everyone will have the same basic form so that they can see their PTO history, hours remaining to be used, etc.

What I want to do is have a button on the form that is visible only if the person is a manager. The button will open the PTO approval form. How can I make a button visible/invisible based on user access levels?

Thanks!

These are some helpfull videos, as mentioned you must set security levels and login screen for users...

Create Login Form Access Database Part 1: http://youtu.be/sWsTwYuWc1o
Create Login Form Access Database Part 2: http://youtu.be/cUjoaxsz92s
Create Login Form Access Database Part 3: http://youtu.be/n7AmISL80Oo
Create Login Form Access Database Part 4: http://youtu.be/dSjWHbJz120

Set Security level: MS Access 2010: http://youtu.be/6GCTqYLTeH8
 
There are name/password fields set up and are used for restricting which forms people can see, etc. I didnt build it so Im not exactly sure how it works. When someone logs in, the login form is still open but the employee dashboard is active.

On the Employees table, each employee has an ID number and there is also a checkbox field for whether someone is on the management team.

I was just poking around and found this on the main dashboard. It shows/hides a tab that is meant to be seen only by HR people.

Code:
Private Sub Form_Load()

    Me.lblMainHeader.Caption = strTitle
    If lManagement <> -1 Then
        Me.NavigationButton7.Width = 0
    Else
        Me.NavigationButton7.Width = 2500
    End If
       
End Sub

The location of the button I want to hide would be located.... Main form (navigation form) ---> Navigation subform (tab named "Paid Time Off").

How would I modify the code above to also hide the button?

Thanks for walking me through this stuff.
 
You haven't said what the name of your button is and which way you would want it to but it would be something like this

Code:
Private Sub Form_Load()

    Me.lblMainHeader.Caption = strTitle
    If lManagement <> -1 Then
        Me.NavigationButton7.Width = 0
    Else
        Me.NavigationButton7.Width = 2500
    End If
    me.buttontohide.visible=not lManagement
  
End Sub
 
You haven't said what the name of your button is and which way you would want it to but it would be something like this

Code:
Private Sub Form_Load()

    me.buttontohide.visible=not lManagement
  
End Sub


That didnt initially work, presumably because the button is on the subform, but once I opened the subform as an individual form and put that code on the OnOpen event, it works!

Thanks for your help!
 
if the button is on a subform, it should be in the form open event of the subform, not the main form
 
basically you need this

Code:
 select case ACTIVEUSER
 case "aaaa": mybutton.visible = false
 case "bbbb": mybutton.visible = true
 end select

so you need a way of determining the activeuser - environ("username") maybe, or your log in form.

you then need a way of determining whether the user gets access to the button or not, which requires a "flag" or a "group" setting associated with the activeuser.

Hence the previous suggestions.
 
After doing some more testing, "lManagement" in the existing code won't work for the level of access desired.

lManagement is set on the login form using:
Code:
lManagement = DLookup("[ManagementTeam]", "[Employees]", "[E-mail Address]='" & Trim$(Me.txtName.Value) & "' and [Password]='" & Trim$(Me.txtPassword.Value) & "'")

and I used

Code:
Me.cmdOpenPTODash.Visible = lManagement
to hide the button.

I want to do the same thing but using lUserAccess which would be based on a different field. Hopefully this will give you enough information to help me....

There are two tables: 1) Employees, 2) LovTable

Employees has basic information including a text field "Role" that is a lookup of a field in LovTable.
Role = SELECT LovTable.UserRole FROM LovTable WHERE (((LovTable.UserRole) Is Not Null));

LovTable is a reference table,
ID UserRole
1 User
2 Manager
3 SuperManager

For the button on the subform, I want it hidden if UserRole = 1 (or Employees.User = "User")


1. How do I set lUserAccess?
2. What code do I use on the subform OnOpen event to to show/hide the button?


Thanks!
 
1. How do I set lUserAccess?
You can use a similar function to your dlookup. What you lookup is unclear to me - perhaps userrole?

2. What code do I use on the subform OnOpen event to to show/hide the button?
The same as previously suggested
 
I think I got it figured out after much trial and error!

Code:
lManagerRole As String

lManagerRole = DLookup("[role]", "[Employees]", "[E-mail Address]='" & Trim$(Me.txtName.Value) & "' and [Password]='" & Trim$(Me.txtPassword.Value) & "'")

And then in the Open event, I used:

Code:
If lManagerRole Like "*manager*" Then
    Me.cmdOpenPTODash.Visible = True
    Else
    Me.cmdOpenPTODash.Visible = False
End If


Thanks for your help!
 
You can put the code to hide the button on the top form OnOpen event:
Me.SubForm.form!Button.Visible = false

I prefer puting it there and not in the subForm's code
 
Private Sub Setpup_Click()

Dim strUName As String
Dim RecordID As Long
Dim AdminRight As String

strUName = CreateObject("WScript.Network").UserName
AdminRight = Nz(DLookup("[Admin_Right]", "tbl_Login_SOP", "[Network_Login] = '" & strUName & "'"))

If AdminRight = "Yes" Then
DoCmd.OpenForm "frm_E_Users"
Else
MsgBox "You don't have permission"
End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom