How to customize "access denied" message?

C

Craig

Hello,

I'm using Access 2003 to develop a database with user-level security. I
have the ULS set up and everything is working well.

When a user attempts to open a form they don't have sufficient privileges to
open, they get the standard message: "You don't have permission to open
'frmForm'."

Is there any way (any property/setting/method/etc.) for me to customize that
message to provide a little more context? I'm afraid less-savvy users might
think that the database is broken, and not understand the real reason they're
getting that message.

Any help is greatly appreciated!

Thanks,
Craig
 
K

Keith Wilby

Craig said:
Hello,

I'm using Access 2003 to develop a database with user-level security. I
have the ULS set up and everything is working well.

When a user attempts to open a form they don't have sufficient privileges
to
open, they get the standard message: "You don't have permission to open
'frmForm'."

Is there any way (any property/setting/method/etc.) for me to customize
that
message to provide a little more context?

You could use the CurrentUser function.

If CurrentUser = "Whatever" Then
MsgBox "Access dennied"
Docmd.Close Form, Me.Name
End If

You'd have to grant them permissions to open the form though.

Keith.
www.keithwilby.com
 
C

Craig

Keith Wilby said:
You could use the CurrentUser function.

If CurrentUser = "Whatever" Then
MsgBox "Access dennied"
Docmd.Close Form, Me.Name
End If

You'd have to grant them permissions to open the form though.

Thanks --- I was hoping there was some kind of database setting or property
where the default "access denied" message comes from.

Or: Some function I could write that would apply to all access-denied
situations, rather than having to write it specifically to a particular user
or form.

Right now there are only a few users, but eventually it will probably grow
to about 25-30 people overall.

Thanks again,
Craig
 
D

david

How are they opening the form? You have more control if you give
them a button to push instead of letting them select forms from the
database window.

(david)
 
K

Keith Wilby

Craig said:
Thanks --- I was hoping there was some kind of database setting or
property
where the default "access denied" message comes from.

Or: Some function I could write that would apply to all access-denied
situations, rather than having to write it specifically to a particular
user
or form.

Right now there are only a few users, but eventually it will probably grow
to about 25-30 people overall.

That's where generic user accounts come in. Instead of having a user
account for each user, consider having an account for each *group* of users,
for example "secretary" or "manager". The other option of course is to
design your GUI such that only valid users can navigate to that form in the
first place so that the error never occurs.

Regards,
Keith.
 
C

Craig

david said:
How are they opening the form? You have more control if you give
them a button to push instead of letting them select forms from the
database window.

(david)

David,

When the database opens, a "main menu" switchboard form appears.

From that form they can click one of four buttons to open additional forms.
Depending on the user's role, he or she might have access to one, two, three,
or all four forms.

I've set up the security correctly and the generic system "access denied"
message appears at the correct moments --- I'd just like to customize that
message. Not a showstopper, just a nice-to-have.

Thanks,
Craig
 
C

Craig

Keith Wilby said:
That's where generic user accounts come in. Instead of having a user
account for each user, consider having an account for each *group* of users,
for example "secretary" or "manager". The other option of course is to
design your GUI such that only valid users can navigate to that form in the
first place so that the error never occurs.

Keith,

Your last reply got me thinking: Is there a function, similar to
CurrentUser, that refers to the security group?

I've set up the user-level security in my database so that I assign
permissions to groups, and then assign users to groups. It would be nice if
the function could check the group, rather than the user.

Thanks again,
Craig
 
K

Keith Wilby

Craig said:
Keith,

Your last reply got me thinking: Is there a function, similar to
CurrentUser, that refers to the security group?

I've set up the user-level security in my database so that I assign
permissions to groups, and then assign users to groups. It would be nice
if
the function could check the group, rather than the user.

This function (written for A97 IIRC) returns True if CurrentUser is a member
of the group supplied as the argument:

Public Function libInGroup(ByVal strGroup As String) As Boolean
Dim ws As DAO.Workspace
Dim usr As DAO.User
Dim strUserName As String
Set ws = DBEngine(0)
strUserName = CurrentUser
For Each usr In ws.Groups(strGroup).Users
If usr.Name = strUserName Then
libInGroup = True
Exit Function
End If
Next
End Function

So maybe you could call that using something like:

If Not libInGroup("MyGroupName") Then
'Access denied
End If

Keith.
 
J

Joan Wild

Craig, use Keith's function in the open event of your 'menu' form.

If Not libInGroup("MyGroupName") then
me!SomeButton.Visible = false
me!SomeOtherButton.Visible = false
etc.
end if

Then your users won't even see the buttons to forms they're not allowed into.
 
K

Keith Wilby

Joan Wild said:
Craig, use Keith's function in the open event of your 'menu' form.

If Not libInGroup("MyGroupName") then
me!SomeButton.Visible = false
me!SomeOtherButton.Visible = false
etc.
end if
Then your users won't even see the buttons to forms they're not allowed
into.

For that matter, you could use

Me.SomeButton.Visible = libInGroup("MyGroupName")

(I think! Not tested).

Keith.
 
D

david

It's been a long time since I looked at a switchboard form, but
it probably has code like this:

On Error GoTo Err_Command0_Click

.....

Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click


If it does not have "On Error", then you will need to add it.

The MsgBox is what displays the error message. In this example
it is displaying the Description as you described.

If you do not already have "On Error" and "MsgBox" in your switchboard
code, Access is using the default code for "On Error" and "MsgBox". The
default can be replaced as shown. Instead of using the control name in
each function, I normally just use

On Error Goto Catch
and
Catch:

(david)
 

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