Determining the current user's permissions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to write some code the will determine whether or not the current
user has Add Rows permission to a table called "Permits", so that I can
enable or disable a button on a form (that adds rows) based on whether or not
they have add row permission. Despite instructions otherwise, many of the
users are trying to click on the Add Permit button to issue a permit instead
of the Issue Permit button which they are supposed to click on. Of course,
since they don't have add rows permission the INSERT query fails, so no harm
is done and they then remember to click on the Issue Permit button instead;
but I would rather just avoid the whole situation by turning off the Add
Permit button if the person isn't allowed to use it

I have not been able to find any way to programmatically determine what a
user's permissions are on a table, how do I accomplish this?

-Harry
 
Hi Harry,

I can't remember the details (if I ever knew them) but IIRC it's basically
something like this:

With CurrentDB.Containers("Tables").Documents("MyTable")
.username = "JoeBloggs"
If .Permissions And dbSecInsertData = dbSecInsertData Then
'user can insert data

End If
End With
 
John,

Thanks, that definitely pointed me in the right direction. This is the code
I came up with:

If (CurrentDb.Containers("Tables").Documents("Permits").AllPermissions And
dbSecInsertData) = dbSecInsertData Then
AddNewPermitButton.Enabled = True
End If

I had to take out the With clause because it didn't work with
CurrentDb.Containers("Tables").Documents("Permits").AllPermissions (it gave
me a "Runtime Error '3420': Object Invalid or no longer set." error as soon
as I tried to access any properties. The username part wasn't necessary since
it fills in the current user automatically. I had to put parentheses around
the AND because operator precedence made it always come up True without the
parentheses.

-Harry
 
Thank you for the feedback.

John,

Thanks, that definitely pointed me in the right direction. This is the code
I came up with:

If (CurrentDb.Containers("Tables").Documents("Permits").AllPermissions And
dbSecInsertData) = dbSecInsertData Then
AddNewPermitButton.Enabled = True
End If

I had to take out the With clause because it didn't work with
CurrentDb.Containers("Tables").Documents("Permits").AllPermissions (it gave
me a "Runtime Error '3420': Object Invalid or no longer set." error as soon
as I tried to access any properties. The username part wasn't necessary since
it fills in the current user automatically. I had to put parentheses around
the AND because operator precedence made it always come up True without the
parentheses.

-Harry
 
Back
Top