Just note that Err.clear only clears the error object.
The error handler is still active. You need to use a Resume statement.
Jim.
Dim intErrorCnt as integer
intErrorCnt = 0
DoCmd.OpenReport "rptScan", acViewReport, , , acHidden
DoCmd.Close acReport, "rptScan", acSaveYes
DoCmd.OutputTo acOutputReport, "rptScan", acFormatPDF, tmpFilePDF
FSO.MoveFile tmpFilePDF, strFilePDF
strFilePDF = ""
Handle_Exit:
Exit Function
Handle_Err:
Select Case Err.Number
Case 2046
intErrorCnt = intErrorCnt + 1
If intErrorCnt > 10 then
Msgbox "Operation failed"
Resume Handle_Exit
Else
Resume
End If
Case Else
MsgBox "unexpected error"
Resume Handle_Exit
End Select
Not sure though what you want to set as a failure.
Jim.
The way it is now with the resume, when a 2046 occurs, the statement that caused the error will re-try. If that occurs more than 10 times, the procedure will exit.
Although it's not quite perfect the way it is. The loop count on the 2046 error is against all the statements. Not sure if that's possible or not (don't remember what 2046 is off-hand).
Jim.
You need a Resume instead of:
GoTo StartPDFConversion: {the line above}
in the error handler. You don't want a goto there as it leaves the error handler active.
I would however add a counter and in the error handler, if it reaches a certain count, then resume with a line that exits the procedure.
Jim.