Group:  Microsoft Access ยป microsoft.public.access.security
Thread: Passwords and alerting users if not authorized

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Passwords and alerting users if not authorized
Ken Cobler 05.06.2006 18:06:01
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.
Re: Passwords and alerting users if not authorized
Scott McDaniel <scott[ at ]NoSpam_Infotrakker.com> 05.06.2006 20:46:50
On Mon, 5 Jun 2006 11:06:01 -0700, Ken Cobler <KenCobler[ at ]discussions.microsoft.com> wrote:

[Quoted Text]
>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[ at ]takemeout_infotrakker.com
www.infotrakker.com

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net