View Full Version : Form Security


Simon Hawkins
01-11-2001, 07:47 AM
Hi,

I have a query which relates to Security and Permissions - I have a form where I want selected fields to be DISABLED when members of the USERS group have logged in, but ENABLED for members of the ADMINS group. So far I have only been able to set permissions for the database as a whole - i.e. read, edit, update etc.


Do I have to set up some VB code (using "IIf CurrentUser" function),or is there an easier way (through assigning permissions?)

Thanks

[This message has been edited by Simon Hawkins (edited 01-12-2001).]

bseche
02-06-2002, 11:01 AM
i'm not an expert. but how about creating 2 form based on the same table one one form you can setup what you want the user to see.
and on the other form all the option you want admin to see.
Than you can assign the users rights to only their form.

SteveA
02-06-2002, 12:19 PM
By default, Access doesn't come with a built in routine that will identify what group(s) the logged in operator belongs to. You will need to write a custom routine that reads through the User and Group classes.

Below is a simple bit of code that will confirm if the current user is a member of the group you specify:



Function GroupAccess(txtGroup as string) as Boolean

Dim wsp as Workspace
Dim grp as Group
Dim blnOK as Boolean

'By default, we assume the user doesn't have access.
blnOK = False
'Set the Workspace to the current workspace
Set wsp = DBEngine.Workspaces(0)
'Loop through each group the current user is a member of and check the name against the passed value in txtGroup
For Each grp In wsp.Users(CurrentUser()).Groups
'If we have a match, set blnOK to True and stop checking
If grp.Name = txtGroup Then
blnOK = True
Exit For
End If
Next grp
'Return the result of the search
GroupAccess = blnOK
End Function


You could use it as follows:


Me.Field1.Visible = GroupAccess("Admins")


or


If GroupAccess("Admins") = True Then
Me.Field1.Visible = True
Me.Field2.Visible = True
Else
Me.Field1.Visible = False
Me.Field2.Visible = False
end If


HTH
SteveA http://www.access-programmers.co.uk/ubb/smile.gif

[This message has been edited by SteveA (edited 02-06-2002).]