Getting "Error: 0" when code runs

P

Pamela

I have a cmdbutton on my form to first spellcheck the record, then e-mail a
snapshot of a related report. All aspects of my code seem to be working
correctly but this "Error: 0" window opens. Any idea what may be causing
this and how to work around it? Thanks!!!!

Pamela

I'll post my code in case it helps:

Private Sub Command47_Click()
On Error GoTo StartOutLook_Error
Dim strDocName As String
Dim strwhere As String
strDocName = "rpt_AssnTest"
strwhere = "[ID]=" & Me!ID
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdSpelling
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.OpenReport strDocName, acPreview, , strwhere
DoCmd.SendObject acReport, strDocName, acFormatSNP, [AppraiserName], , ,
[Claim Number] & " New Assignment", "Here's this new assignment. Please
contact the owner as soon as possible. Thanks!"
DoCmd.Close acReport, "rpt_AssnTest"
StartOutLook_Error:
If Err <> 2501 Then ' Ignore the error
MsgBox "Error: " & Err & " " & Error
End If

Exit_Command47_Click:
Exit Sub

Err_Command47_Click:
MsgBox Err.Description
Resume Exit_Command47_Click

End Sub
 
K

Ken Snell [MVP]

Your code always runs through the StartOutLook_Error block. Change the code
to this:

Private Sub Command47_Click()
On Error GoTo StartOutLook_Error
Dim strDocName As String
Dim strwhere As String
strDocName = "rpt_AssnTest"
strwhere = "[ID]=" & Me!ID
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdSpelling
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.OpenReport strDocName, acPreview, , strwhere
DoCmd.SendObject acReport, strDocName, acFormatSNP, [AppraiserName], , ,
[Claim Number] & " New Assignment", "Here's this new assignment. Please
contact the owner as soon as possible. Thanks!"
DoCmd.Close acReport, "rpt_AssnTest"

Exit_Command47_Click:
Exit Sub

Err_Command47_Click:
MsgBox Err.Description
Resume Exit_Command47_Click

StartOutLook_Error:
If Err <> 2501 Then ' Ignore the error
MsgBox "Error: " & Err & " " & Error
End If
Resume Exit_Command47_Click

End Sub
 
D

Dirk Goldgar

Pamela said:
I have a cmdbutton on my form to first spellcheck the record, then e-mail a
snapshot of a related report. All aspects of my code seem to be working
correctly but this "Error: 0" window opens. Any idea what may be causing
this and how to work around it? Thanks!!!!

Pamela

I'll post my code in case it helps:

Private Sub Command47_Click()
On Error GoTo StartOutLook_Error
Dim strDocName As String
Dim strwhere As String
strDocName = "rpt_AssnTest"
strwhere = "[ID]=" & Me!ID
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdSpelling
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.OpenReport strDocName, acPreview, , strwhere
DoCmd.SendObject acReport, strDocName, acFormatSNP, [AppraiserName], ,
,
[Claim Number] & " New Assignment", "Here's this new assignment. Please
contact the owner as soon as possible. Thanks!"
DoCmd.Close acReport, "rpt_AssnTest"
StartOutLook_Error:
If Err <> 2501 Then ' Ignore the error
MsgBox "Error: " & Err & " " & Error
End If

Exit_Command47_Click:
Exit Sub

Err_Command47_Click:
MsgBox Err.Description
Resume Exit_Command47_Click

End Sub


Your error-handling isn't right. Your "StartOtLook_Error" error handler
will display a message whenever you make it through without errors, and your
"Err_Command47_Click" error handler will never be executed under any
circumstances. Try this:

'------ start of revised code ------
Private Sub Command47_Click()

On Error GoTo Err_Command47_Click

Dim strDocName As String
Dim strwhere As String

strDocName = "rpt_AssnTest"
strwhere = "[ID]=" & Me!ID

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdSpelling
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.OpenReport strDocName, acPreview, , strwhere

DoCmd.SendObject acReport, strDocName, _
acFormatSNP, [AppraiserName], , , _
[Claim Number] & " New Assignment", _
"Here's this new assignment. Please contact " & _
"the owner as soon as possible. Thanks!"

DoCmd.Close acReport, "rpt_AssnTest"

Exit_Command47_Click:
Exit Sub

Err_Command47_Click:
If Err = 2501 Then
' Ignore "action cancelled" error.
Else
' Display message for other errors.
MsgBox "Error: " & Err.Number & ": " & Err.Description
End If
Resume Exit_Command47_Click

End Sub
'------ end of revised code ------
 

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