enable/disable command button according to user security

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
 
J

John Viescas

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)
 
A

Applebaum

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top