asked on
Is there a way to force a retry on error?
The scan function works great. It drops the image into a local file as a jpg, no problem.
I open the jpg(s) in a report, which works.
I close the report, using acSaveYes, and this seems to be working correctly.
Where I run into issues (at least on the AccessRuntime side of things) is in this line
DoCmd.OutputTo acOutputReport, "rptScan", acFormatPDF, "C:\TempScan\Report.pdf"
In the Runtime environment, I frequently get a 2046 error, and it stops.
If we rerun the process (sometimes multiple times) it goes through with the exact same results.
I added in a statement to try to get around this, by having it loop back to the portion of the code above in the Handle_err
Select Case Err.Number
Case 2046
GoTo StartPDFConversion: {the line above}
End Select
Rather than loop, its still coming up with the 2046 error.
I am using RT2013 as I was seeing too many bugs with RT2016.
Is there a better way to force a retry of the PDF outputting code so that it just retries again?
Any help would be greatly appreciated.
Jeff
ASKER
Just note that Err.clear only clears the error object.
The error handler is still active. You need to use a Resume statement.
Jim.
ASKER
The error 2046 is the "outputto is not available" message that comes up in so many questions. I have my code in question below:
---
DoCmd.OpenReport "rptScan", acViewReport, , , acHidden
DoCmd.Close acReport, "rptScan", acSaveYes
DoCmd.OutputTo acOutputReport, "rptScan", acFormatPDF, tmpFilePDF
Handle_Exit:
Exit Function
Handle_Err:
Select Case Err.Number
Case 2046
Err.Clear
Resume StartPDFConversion:
End Select
---
But the error is still popping up probably 1 in 5 times. Am I handling the error incorrectly? I recently added in the Err.Clear and Resume statements as suggest, and changed it from just RESUME to as shown (thats the header for the start of the create PDF process). Originally, I was just calling a GoTo StartPDFConversion, which also failed.
The odd thing is I have a handler for there being nothing in the scanner, which sends the process back using RESUME, and that works fine (even without the Err.Clear).
Yes, I do know I do not have a loop break set up in this yet, first I just want to get the err handler to retry.
If we manually restrart the process, the scan will USUALLY go through the second time, so my hope is to have the system automatically retry on failure to save the extra staff effort. Any suggestion?
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.
ASKER
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.
A big question would be why it seems to be haphazard.
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.