Access Runtime Error Number: 0

M

Mike

I've implemented the below code into an Access database
so that users can fax reports using our Shared Fax
Service. The code works perfectly and faxes are sent
successfully. But when the code is finished running
user's get the message:

Error Number: 0

What is causing this error to occur? Is this anything
serious? Thank you.
-------------------------------------------------------
Option Compare Database
Option Explicit
Function FaxReport()

Dim FaxDocumentObj As New FAXCOMEXLib.FaxDocument
Dim FaxServerObj As New FAXCOMEXLib.FaxServer
Dim JobIDObj As Variant
Dim CurrentReport As Report

'Error handling.
On Error GoTo Error_Handler

'Identify the active report.
Set CurrentReport = Screen.ActiveReport

'The report is first saved to file, THEN the FILE is sent
via fax
DoCmd.OutputTo acOutputReport, CurrentReport.Name, _
acFormatRTF, "Rpt.rtf", False

'Connect to the fax server.
FaxServerObj.Connect "faxservername"

'Set the fax body.
FaxDocumentObj.Body = "c:\1fax.txt"

'Name the document.
FaxDocumentObj.DocumentName = "Fax"

'Set the fax priority.
FaxDocumentObj.Priority = fptHIGH

'Add the recipient fax number.
FaxDocumentObj.Recipients.Add "8888888888", "Mike"

'Choose to attach the fax to the fax receipt.
FaxDocumentObj.AttachFaxToReceipt = True

'Set the cover page type and the path of the cover page.
FaxDocumentObj.CoverPageType = fcptSERVER
FaxDocumentObj.CoverPage = "StandardCP"

'Provide the cover page note.
FaxDocumentObj.note = "Attached you will find your quote
(s). Thank you for your business."

'Provide the address for the fax receipt.
FaxDocumentObj.ReceiptAddress = "(e-mail address removed)"

'Set the receipt type to e-mail.
FaxDocumentObj.ReceiptType = frtMAIL

FaxDocumentObj.Subject = "Quote"

'Set the sender properties.
FaxDocumentObj.Sender.Name = "SenderName"
FaxDocumentObj.Sender.Company = "CompanyName"

'Save sender information as default.
FaxDocumentObj.Sender.SaveDefaultSender

'Submit the document to the connected fax server, and
retrieve the job ID.

JobIDObj = FaxDocumentObj.ConnectedSubmit(FaxServerObj)

MsgBox "The fax is being sent." & vbCrLf & "You will
receive a transmission status via e-mail in 3-5 minutes."

Error_Handler:
'Implement error handling at the end of your
subroutine. This implementation is for demonstration
purposes
MsgBox "Error number: " & Hex(Err.Number)

End Function
-------------------------------------------------------
 
N

Norman Yuan

Err.Number=0 means NO ERROR.

You should put Exit Function (Sub) before Error_Handler: label, so that if
no error occurs, the code in Error_Handler will not executed. Or you do
this:

Error_Handler:
If Err.Number<>0
MsgBox "Error number: " & Hex(Err.Number)
End If
End Function
 
J

Jeff Conrad

Hi Mike,

Your code has an error handler routine, but the only place to exit the routine is below the error.
Code will progress normally from top to bottom unless told otherwise. Your code completes
everything, but then reaches the error handler and you tell it to display an error whether or not
one actually occurred. You need to have an exit function area above the error handler. The following
illustration may help:

Public Function SomeFunction()
On Error GoTo ErrorPoint

' Regular code here

ExitPoint:
Exit Function

ErrorPoint:
' Some way to display or ignore the error
Resume ExitPoint

End Function

So once the regular code is finished it comes to the ExitPoint and is told to leave the function.
The ErrorPoint code should ONLY be reached if a true error has occurred. We then tell the code to go
back to the ExitPoint and exit gracefully. We generally want to have only one entry point for code
and one exit point. Does this make sense?

I would change the bottom part of your code to this:

Exit_Point:
Exit Function

Error_Handler:
'Implement error handling at the end of your
'subroutine. This implementation is for demonstration purposes
MsgBox "Error number: " & Hex(Err.Number)
Resume Exit_Point

End Function

That should take of it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top