Error trapping

jason_nevin

Registered User.
Local time
Today, 18:16
Joined
Nov 22, 2002
Messages
46
I've developed a report which uses code to set the properties of a picture control in-flight. I use this method to display unbound jpegs. Occasionally a file name is incorrectly entered and when the report runs it fails because the file does not exist. When running the report in form view an error is displayed with a meaningful message. However, if the report is printed from VBA no error is displayed, the report simply stops. As you can appreciate this is a bit confusing for the end user. Is there a way of trapping and displaying the error when printing a report?
 
Jason,

I'd make a nice picture conveying "Not Available": NoPicture.jpeg

I'd make a Public Function:

Code:
Public Function IsFileOK(FileToCheck As String) As String
  If Dir(FileToCheck) = "" Then
     IsFIleOK = "NoPicture.jpeg"
  Else
     IsFileOK = FileToCheck
  End If
End Function

Then, just put a new field in your report's query:

NewField: IsFileOK([YourFilenameField])

Use that column in your report it will have a valid picture, or
your new "Not Available" picture.

btw,
The Public Function can have the code that you currently use on
your form. It obviously works.

Wayne
 
Thanks Wayne. I'll try that. Can I assume then that errors cannot be trapped and reported during the printing process? There are other potential problems that could occur that I would like to make provision for.
 
Jason,

You could put the function's code in the DetailFormat event of your report,
and if the file is not present, do whatever you want.

The previous solution is just an easy way to let your report function, and
gracefully display a default picture when no file is available.

What are the "other problems"?

Wayne
 
It does not sound like your are using any error handlers to trap for any unexpected errors?
Code:
Private Sub cmdPrintRec_Click()
On Error GoTo Err_cmdPrintRec_Click
    
'your code here
 
Exit_cmdPrintRec_Click:
    Exit Sub
 
Err_cmdPrintRec_Click:
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_cmdPrintRec_Click
    
End Sub
Use something like this if you are trapping for specific error numbers...
Code:
Private Sub cmdPrintRec_Click()
On Error GoTo Err_cmdPrintRec_Click
     
'your code here
 
Exit_cmdPrintRec_Click:
    Exit Sub
 
Err_cmdPrintRec_Click:
    If Err.Number = 666 Then
        MsgBox "Houston, we have a serious problem!", vbCritical, "Help!"
        Exit Sub
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_cmdPrintRec_Click
    End If
    
End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom