Changing form properties based on group permissions

Z34Lee

Registered User.
Local time
Today, 07:04
Joined
Dec 8, 2006
Messages
22
Is it possible to change form properties based on the group that the current user is in? I'm not sure if there is a way to get a user's workgroup information in code.

The reason I ask is that in order for certain actions to work properly, I have to give one group update permissions to a table. Unfortunately, this leaves the information open for edits in a subform, which I don't want. I could change the properties of the form and subform itself, but I would like to be able to edit the data within the form. Ideally, the form wouldn't allow edits unless I am the one using the form. Any ideas?
 
The built in security should be able to help, however you can also use: environ("workgroup") to get the workgroup the computer is on.
 
In my case, the security is fighting against me a bit. I need that group to have update permissions for the table in question, but I don't want those permissions when used on a particular form.

Is there a way to not only determine which workgroup they're in (everyone who uses the database will be in the same workgroup), but determine the group within the workgroup they are in?
 
The built in security should be able to help, however you can also use: environ("workgroup") to get the workgroup the computer is on.

Environ("workgroup") returns Null and no Environ property will return the workgroup. The following code will loop you through all of the available Environ properties:

Code:
Sub showenviron()
Dim x As Integer
For x = 1 To 33
MsgBox ("Environ " & x & " " & Environ(x))
Next x
End Sub

The following code should help you out as an alternative.
Add this to a module (declare 'Public adminsyes as Integer' in top section of module):

Code:
Public Function CheckForAdmin()
Dim wrkDefault As Workspace
Dim usrLoop As USER
Dim grpLoop As Group
Dim curuser
adminsyes = 0
curuser = CurrentUser
Set wrkDefault = DBEngine.Workspaces(0)
With wrkDefault
For Each usrLoop In .Users
    If usrLoop.Groups.Count <> 0 Then
        For Each grpLoop In usrLoop.Groups
        If usrLoop.name = curuser And grpLoop.name = "Admins" Then
        adminsyes = 1
        Exit Function
        End If
        Next grpLoop
    End If
Next usrLoop
End With
End Function

Add this to your form:

Code:
Call CheckForAdmin
If adminsyes <> 1 Then
    ' Set your form properties how you want them if the logged in user is not in the Admins group
End If
 
Last edited:

Users who are viewing this thread

Back
Top Bottom