Home All Groups Group Topic Archive Search About

Passwords and alerting users if not authorized

Author
5 Jun 2006 6:06 PM
Ken Cobler
I have a database with levels of authorization for either "Admin" or "Users".
Two questions:

1.  If a user wants to open a form in edit mode, they are not allowed and
receive an error message.  So far so good.

I would now like them to receive a MsgBox message, like "You are not
authorized to use this form".  I am not sure which event to attach the code
on.  Please advise.  (OnError does not seem to work.)

2.  Can I grey-out menu items depending on the user's authorization?  Or do
I have to make multiple menus?

Thank you.

Author
5 Jun 2006 8:46 PM
Scott McDaniel
On Mon, 5 Jun 2006 11:06:01 -0700, Ken Cobler <KenCob***@discussions.microsoft.com> wrote:

>I have a database with levels of authorization for either "Admin" or "Users".
> Two questions:
>
>1.  If a user wants to open a form in edit mode, they are not allowed and
>receive an error message.  So far so good.
>
>I would now like them to receive a MsgBox message, like "You are not
>authorized to use this form".  I am not sure which event to attach the code
>on.  Please advise.  (OnError does not seem to work.)

You'd be better off determining if they can open the form BEFORE they open it ... something like the code snippet below:

Sub btnOpenMyForm_Click()

<other code>

If Not UserInGroup(CurrentUser, "Admins") Then
  Msgbox "Sorry, you can't open this form"
Else
DoCmd.OpenForm "YourForm"
End If

End Sub

'/Note: This function culled from a newsgroup posting by Sandra Daigle
Function UserInGroup(strUser As String, strGroup As String) As Boolean
    Dim strUserName As String
    On Error Resume Next    
    strUserName =DBEngine.Workspaces(0).Groups(strGroup).Users(strU ser).Name
    IsUserInGroup =(Err = 0)
End Function

I've been having trouble reaching the online version of the Security FAQ recently, but here's a downloadable version:
http://support.microsoft.com/kb/207793/en-us

>
>2.  Can I grey-out menu items depending on the user's authorization?  Or do
>I have to make multiple menus?

You can enable/disable menu items based on group membership. You'd first determine group memberships using the code as
above, then you can use the example at the link below to enable/disable menu items:

http://support.microsoft.com/?kbid=198464

>
>Thank you.

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com