I get a Blank MsgBox using "Msgbox Err.Description"

I programmed an Access Database for a friend.  I used to never use Msgbox for errors (I would just delete the "Error_Handler" or would not put it in if I wrote some custom code in VBA).

Recently I started using the MsgBox as there were errors that I knew would come about, and I wanted to add a human description to it, so a non-VBA user could understand what was happening.  Some of my boxes work, but for some reason, I have several buttons that click (i.e., to open a report), the report opens fine, but then once it has executed the command, it displays a blank msg box (no title, no error message, vbOKonly button) and one can click it and continue working.

The code I used for one of them was:

On Error Goto Err_handler

DoCmd.OpenReport "r_QuarterlyChecklist", acViewPreview

Err_handler:

Msgbox Err.Description

End Sub

I looked around the web, but found nothing.  Any ideas?

Thanks.

Adam
Answer
Answer

I hate to quibble with my fellow MVPs, but it's recommended that you do a Resume (or Err.Clear) once you've reported the error:

Private Sub Something_Click()
    On Error Goto Err_handler

    DoCmd.OpenReport "r_QuarterlyChecklist", acViewPreview
 
End_handler:
    Exit Sub
Err_handler:
    Msgbox Err.Description
    Resume End_handler
 
End Sub
 
The reason for directing the program back to End_handler is for those cases where you might have cleanup that has to run whether or not the code was successful.
 
You might read Allen Browne's Error Handling in VBA
Doug Steele, Microsoft Access MVP
www.AccessMVP.com/djsteele

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated June 13, 2023 Views 4,533 Applies to: