Not sure why you want to print it out. I use a screen capture utility (like Greenshot) to capture an error message so I can then look at the code and the message. Setting breakpoints above the location where you think the error occurs works well too. An invaluable help is to include a Resume line in the error handling section of each module:
Code:
cmdFilter_Click_Error: Call ErrorHandler(MODULE_NAME, "cmdFilter_Click", Err, Err.Description)
Resume cmdFilter_Click_Cleanup
Resume
Before running the code, set a breakpoint on the first executable line of your error handling section (in my case, Call ErrorHandler...). Then when the error occurs, execution stops on that line. Move the cursor from the breakpoint line to the "Resume" line and press F8. It will take you to the line that caused the error. I presume you include error trapping in your modules? Here is a complete procedure:
Code:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Form_Open_Error
Call FormAutoExec(Me, True)
...
Form_Open_Cleanup:
Exit Sub
Form_Open_Error:
Call ErrorHandler(MODULE_NAME, "cmdCancel_Click", Err, Err.Description)
Resume Form_Open_Cleanup
Resume
End Sub
Also, this link may help you learn more about debugging techniques: http://www.fmsinc.com/tpapers/vbacode/debug.asp