Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Error Messages for Access Security 3

Status
Not open for further replies.

wbwillson

Technical User
Oct 7, 2002
52
GB
How can I replace the error message that comes up when a user tries to access a portion of the database to which they don't have permission. For example when a user clicks on a button on my form which runs a macro to open another form they get the following error "You don't have permission to run 'macroname'". This doesn't list any error number (Just an exclamation). How can I change this message to something of my own? Any ideas? I know how to change it if I had the error number, but since it doesn't display the number I can't change it. Thanks for any suggestions!

Bill
 
Below is the VBA I would place in the OnClick event of your button called cmdRunMacro that runs the macro called mcrTest. The error handler includes the error number, so you can then use either If or Select statements to handle different error numbers to your heart's content.

Code:
Private Sub cmdRunMacro_Click()
On Error GoTo Err_cmdRunMacro_Click

    DoCmd.RunMacro "mcrTest"

Exit_cmdRunMacro_Click:
    Exit Sub

Err_cmdRunMacro_Click:
    MsgBox Err.Number & ": " & Err.Description, vbExclamation
    Resume Exit_cmdRunMacro_Click
    
End Sub

HTH. [pc2]
 
Hmm. I would tend to test if the person has the permission first, so that I wouldn't send the same error message for every error. But I would also not use macros, so I would be trapping for more errors.

In the Access Security FAQ (I _think_ that's where I got it), there's code to check if a the current user is a member of a specific security group. Run and if/then structure on that function to either open the form or tell the person they don't have the permission to do this.

Actually, what I do in my applications is check this when they open the form that has the button on it. If they don't have the permission, I disable the button.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Jeremy makes a good point about not using macros. But that's another story [smile]

There's a version of a function you can use to test security group membership at - I would go one step further and actually make the button invisible rather than just disabling it if the user doesn't have the privs. Why show the user what they can't use? But I guess that's just a personal preference. [pc2]
 
Jeremy,

Thats for the info, I'll see about converting my macros to VBA. Thanks also for the link mp9 (sorry don't know your name)..all of this info is very helpful! Thanks alot!

Bill
 
Yeah, much better to make the button invisible. When I wrote about disabling it, I knew I was saying something goofy, but I couldn't put my finger on it.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Linda,

Thanks, those error codes worked perfectly! How did you figure out what the error codes were? Access didn't show the error code when the error actually occured? Thanks again!

Bill
 
Bill,

By working in macros you lose a lot of information about and ability to control errors.

If you convert your macro to code (there's a menu item that does that), and then run the code instead of the macro, you'll see the error messages.

This is one of the really big parts of that other story mp9 was talking about.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Jeremy,

I've converted most of my macros to code, and it is much easier to manipulate them now. I already have a lot of code controlling the database so it only makes sense to convert the macros as well. Thanks again for your advice and tips, I really appreciate it!

Bill
 
Glad to help Bill. That's what the forum's for. I got so much help from a forum like this when I was starting out that it feels relatively important to me to give back a little.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Jeremy,
Thanks for replying to my other thread, and sending me to this one.
One more question:
Is there a way to put in custom icons or pictures onto an error MsgBox, (for ex. a company logo)?
Thanks.
Steve
 
Steve,

Glad to help.

Can't do that, but you can design your own form to use instead of message boxes. And if you make a custom function to do the work of opening it, you can have it function much like a messagebox.

Actually sounds like a nice little project, though I'm not sure I'll have time to do it at any point soon.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
If you look at the Visual Basic code for one your procedures, you'll see a label for error handling. It'll have the following code :

MsgBox err.Description
Resume ExitcmdButton

Comment the code out and insert the following in (this is all one line, though it might not show up that way in the message):

MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description

This will tell you what the error number is and give you a short description.

Linda Adams
Linda Adams/Emory Hackman Official Web site Official web site for actor David Hedison:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top