Form level security

  • Thread starter Thread starter JohnC
  • Start date Start date
J

JohnC

I have an application with User Level Security. There are two tables with a
one-to-one relationship. This was designed so that different permissions
could be assigned to users depending on whether they could edit one or the
other table.

I am finding that this degree of security is probably not needed and I would
like to combine the two tables into one. This is in part being driven by a
need to simplify and reduce database objects.

The application will still have User Level Security. I want to still
restrict what users can edit or not edit and I think I want to do this using
the form. So I want the form to recognize the user, determine what group
they belong to, and enable/disable controls accordingly.

Can somebody point me in the right direction? Is this described in a book?

Thanks for your help.

John C
 
Here is a simple function that you can code into your form
to determine whether the current user is a member of a
particular group (in this case Admins)

Private Function IsAdmin() As Boolean
Dim varTemp As Variant
On Error GoTo lbl_err

varTemp =
DBEngine.Workspaces(0).Users(CurrentUser()).Groups("Admins").Name
IsAdmin = True
Exit Function

lbl_err:
IsAdmin = False

End Function

You could then put code into the form's Load eventhandler
to disable or hide specific controls e.g.

Private Sub Form_Load()
If IsAdmin Then
Me.txtFieldA.Enabled = True
etc
Else
Me.txtFieldA.Enabled = False
etc
End If
End Sub

Hope This Helps
Gerald Stanley MCSD
 
Works perfectly. Thanks Gerald.
JohnC

Gerald Stanley said:
Here is a simple function that you can code into your form
to determine whether the current user is a member of a
particular group (in this case Admins)

Private Function IsAdmin() As Boolean
Dim varTemp As Variant
On Error GoTo lbl_err

varTemp =
DBEngine.Workspaces(0).Users(CurrentUser()).Groups("Admins").Name
IsAdmin = True
Exit Function

lbl_err:
IsAdmin = False

End Function

You could then put code into the form's Load eventhandler
to disable or hide specific controls e.g.

Private Sub Form_Load()
If IsAdmin Then
Me.txtFieldA.Enabled = True
etc
Else
Me.txtFieldA.Enabled = False
etc
End If
End Sub

Hope This Helps
Gerald Stanley MCSD
 
Can other group names be included with Admins? In other words allow several
groups to have controls enabled?

JohnC
 
The neatest way to go about this would be to parameterise
the group name into the Is function, then have an extended
if statement in the Load eventhandler e.g.

Private Function IsMember(ByVal GroupName As String) As Boolean
Dim varTemp As Variant
On Error GoTo lbl_err

varTemp =
DBEngine.Workspaces(0).Users(CurrentUser()).Groups(GroupName).Name
IsMember = True
Exit Function

lbl_err:
IsMember = False

End Function

Private Sub Form_Load()
Dim boolEnableControls As Boolean

If IsMember("Admins") Then
boolEnableControls = True
ElseIf IsMember("Supervisors") Then
boolEnableControls = True
etc
Else
boolEnableControls = False
End If

If boolEnableControls Then
Me.txtFieldA.Enabled = True
etc
Else
Me.txtFieldA.Enabled = False
etc
End If
End Sub

Hope This Helps
Gerald Stanley MCSD
 
Back
Top