enable/disable command button according to user security

  • Thread starter Thread starter Applebaum
  • Start date Start date
A

Applebaum

Hello,

Can anyone show me how to disable/enable a command button on a form
according to the current user and/or group?

I'd have thought it a common scenario - to have administrative buttons only
enabled for administrators, but I can't find many postings answered.

Many thanks in advance!

Matthew
 
I assume you're talking about the Access user name, not Windows. You can
use CurrentUser to find out the name of the signed-on user. You'll need to
look through all the groups for that user to determine what groups the user
belongs to. Or, if you're trying to find out if the current user is a
member of a specific group, you can attempt to fetch that group object from
the user inside an error trap. Like this:

Dim ws As DAO.Workspace, grp As DAO.Group

Set ws = DBEngine(0)
' Find out if the current user is a member of the "Managers" group
On Error Resume Next
Set grp = ws.Users(CurrentUser).Groups("Managers")
If Err <> 0 Then ' .. not a member if got an error

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out" (coming soon)
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
 
Thank you, that helps perfectly!

Matthew


John Viescas said:
I assume you're talking about the Access user name, not Windows. You can
use CurrentUser to find out the name of the signed-on user. You'll need to
look through all the groups for that user to determine what groups the user
belongs to. Or, if you're trying to find out if the current user is a
member of a specific group, you can attempt to fetch that group object from
the user inside an error trap. Like this:

Dim ws As DAO.Workspace, grp As DAO.Group

Set ws = DBEngine(0)
' Find out if the current user is a member of the "Managers" group
On Error Resume Next
Set grp = ws.Users(CurrentUser).Groups("Managers")
If Err <> 0 Then ' .. not a member if got an error

--
John Viescas, author
"Microsoft Office Access 2003 Inside Out" (coming soon)
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/
(Microsoft Access MVP since 1993)
 
Back
Top