Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding controls from SOME users 1

Status
Not open for further replies.

nivlac

Technical User
May 9, 2001
25
US
I'm sure this will be simple, but I'm brain-fried. I have a database set up with user and group level security. Iwould like most users to see a simple data-entry form, while a select few can see the same form with additional controls only visible to them. How can I get Access to look at the current user when the form is openned and determine which controls the user is allowed to see? Make sense?

Thanks for your help!
Nivlac
 
In the OnOpen event you can do something like this:

If CurrentUser = "UserToAllow" then
Control1.Visible = True
Control2.Visible = True
Control3.Visible = True
Control4.Visible = True
End If

HTH
Joe Miller
joe.miller@flotech.net
 
Nivlac:

The way I do this is to create a table called tblUsers. Consists of three fields: SystemName, UserName, PermissionLevel. Permission Level determines which forms the user can access (I usually set the Enabled property of the command button to False rather than set the Visible property to False.)

In the On_Open event of the form where the command buttons are, use code that tests the value of the Permission Level; DLookup will work well:

Dim Perm as integer

Perm = DLookup("PermissionLevel", "tblUsers", "SystemName = '" & CurrentUser & "'"

And then some decision logic:

If perm = 1 then
'Allow all buttons
elseif Perm = 2 then
cmdForm.visible = false

etc.

Hope this helps.

Larry De Laruelle
larry1de@yahoo.com

 
Thanks for the help. It works great!

Nivlac
 
A similar thing to try and I think more exactly what you are after is to implement the user/user level table giving each user a level.

Then for each control - this bit is a drag, I know - set the tag property to a specific level, eg, view record tag = 1, delete record tag = 10.

Create a routine in a module that is called upon opening each form that cycles through each control checking the user level against the tag value - if the user level isn't as high, set visible to False.

As I said, it does take time to set up, but is very effective.

Hope this helps,

Jes
 
Hi!

There is function for validation of permissions of users and/or user groups.

Example:
me.control1.visible = IsUserInGroup(, "AllowSeeControls")

Function IsUserInGroup(Optional strUser As String = "", Optional strGroup As String = "") As Boolean
'This is function for verifying of user's group
'If is omitted strUser (user name), CurrentUser is verified
'If is omitted strGroup (user group), "Admins" group is verified
On Error GoTo Err_IsUserInGroup
Dim usr As User

If strUser = "" Then strUser = CurrentUser
If strGroup = "" Then strGroup = "Admins"

Set usr = DBEngine.Workspaces(0).Groups(strGroup).Users(strUser)

'If group <strGroup> have not user <strUser> then error is generated
IsUserInGroup = True

Exit_IsUserInGroup:
Exit Function

Err_IsUserInGroup:
If Err.Number <> 3265 Then
'3265 >>> Item not found in this collection:
'consequently IsUserInGroup = False
MsgBox &quot;Error No &quot; & Err.Number & vbLf & Err.Description, , &quot;Function IsUserInGroup&quot;
End If
Resume Exit_IsUserInGroup

End Function


I hope this will little help you.

Aivars

alaganovskis@hotmail.com

 
If CurrentUser = &quot;UserToAllow&quot; then
Control1.Visible = True
Control2.Visible = True
Control3.Visible = True
Control4.Visible = True
End If


You can be SURE if it is Westinghouse (or has an else clause?)

If CurrentUser = &quot;UserToAllow&quot; then
Control1.Visible = True
Control2.Visible = True
Control3.Visible = True
Control4.Visible = True
Else
Control1.Visible = False
Control2.Visible = False
Control3.Visible = False
Control4.Visible = False
End If


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Larry,

(I usually set the Enabled property of the command button to False rather than set the Visible property to False.)

While either enabled or visible deny access to the control, setting enabled leaves the control visible to the user. In some (many?) organizations, this will generate some political activity (why am I not allowed access to THIS ....


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Michael:

Very good point.

I originally set it up this way since setting the visible property to false would have left gaps in my menu system and I was too lazy to reorganize the form.

Mostly, though, it has been an issue of allowing access to data entry forms for those who do that dirty deed and allowing managers access to view the data and run report.

Fortunately, I work for a medium size organization and, so far, that particular beast has not raised it's head.
Larry De Laruelle
larry1de@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top