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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identifying usergroups in vba 2

Status
Not open for further replies.

JaneInMA

Programmer
Nov 3, 2000
104
US
If you have set up your database to have different levels of security I was wondering if there was a way to detect the level of authority in VBA and set up locking accordingly. I know you can use CurrentUser to identify a user but I want to be able to allow or stop a person changing a field depending on whether they have admin permissions.
Scenario:
On current
Check level
if level=Admin
Field.locked = False
Else
field.locked = True
End If
Or do I just really want Oracle..........
Thanks
 
Yup, you can, if it's a Jet database. Here's some sample code. The first part checks for Admin permission on the database. The second checks for Admin permission on a table named "MyTable". (Note: If you're using Access 2000, you must set a reference to the Microsoft DAO 3.6 Object Library.)
Code:
    Sub CheckUserLevel()
        Dim db As Database
        Dim doc As Document
        
        Set db = CurrentDb()
        Set doc = db.Containers("Databases").Documents("MSysDb")
        If (doc.AllPermissions And dbSecDBAdmin) <> 0 Then
            Debug.Print &quot;User is DB Admin&quot;
        End If
        
        Set doc = db.Containers(&quot;Tables&quot;).Documents(&quot;MyTable&quot;)
        If (doc.AllPermissions And dbSecWriteSec) <> 0 Then
            Debug.Print &quot;User has Admin permission on table&quot;
        End If
        
        Set doc = Nothing
        Set db = Nothing
    End Sub
The &quot;AllPermissions&quot; property returns the union set of permissions granted to the user and to each group the user belongs to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top