message box popping up with no message string

T

tw

Every once in a while I get what looks like the msgbox popping up with
Microsoft Access as the title of the window, no message, and an ok button.
I don't know where this box is coming from, I don't have any code that I can
find that would pass an empty string to msgbox(). I am using msgbox() in
some error routines where the string should be err.description. Is there
ever a case where err.description would be blank if an error occurs? If
that is the case what could the error be, if that is not the case, then does
anyone know why this box might be popping up?
 
N

Norman Yuan

It must be caused by your code. When error occurs, the Err.Description is
"", in this case, MsgBox Err.Description will show a blank message box. It
seems your code falls through the error handler code even there is not
error. Check for missing "Exit Sub" or "Exit Function" that bypasses error
handling code.
 
J

Jerry Porter

I agree with Norman. If the spot is hard to find, try this: when the
blank MsgBox appears, press Ctrl/Break. That should interrupt the code,
and selecting "Debug" from the dialog that appears should put in the
code right after the line that displayed the MsgBox.

Jerry
 
M

Mark

I think it depends on when you're looking at err.description. If you don't
display the message box right away in your error-handler, then set a string
variable to the err.description. I think I remember hearing that err.number
and err.description can sometimes get cleared if something else happen along
the way before you actually want to use it.
 
T

tw

I pressed ctrl/Break and this is where the code that was running... The
cursor is at the exit sub statement. The form "FRM Scheduling" opens fine.
It is an unbound form with some command buttons on it. However this is not
the only place this is happening. I think I should have an application
lever on error routine, but I'm not sure how/where to put it. I'm not that
familiar with access.

Private Sub Command40_Click()
On Error GoTo exitsub
DoCmd.OpenForm "FRM Scheduling", acNormal
exitsub:
MsgBox Err.Description
Exit Sub
End Sub
 
T

tw

There is also no code in the form that loads until a command button is
clicked, so how do I find an error if it is occurring when this form is
being loaded?
 
D

Dirk Goldgar

tw said:
I pressed ctrl/Break and this is where the code that was running...
The cursor is at the exit sub statement. The form "FRM Scheduling"
opens fine. It is an unbound form with some command buttons on it.
However this is not the only place this is happening. I think I
should have an application lever on error routine, but I'm not sure
how/where to put it. I'm not that familiar with access.

Private Sub Command40_Click()
On Error GoTo exitsub
DoCmd.OpenForm "FRM Scheduling", acNormal
exitsub:
MsgBox Err.Description
Exit Sub
End Sub

That code will display the message box whether there is an error or not,
and if there is no error, Err.Description (the description of the
current error) will be a zero-length string. So you'll get a blank
message box. The code should look like this:

Private Sub Command40_Click()

On Error GoTo ErrorHandler

DoCmd.OpenForm "FRM Scheduling", acNormal

ExitPoint:
Exit Sub

ErrorHandler:
MsgBox Err.Description
Resume ExitPoint

End Sub

The labels "ErrorHandler" and "ExitPoint" are arbitrary, of course. The
imnportant point is that putting the error-handling code *after* the
Exit Sub statement ensures that error-handling code is only executed
when there is in fact an error.
 
Top