SendObject action was cancelled

S

scadav

Within a module, I have the following:



Public Function SendEmail(sClient As String, sDateRequested As String,
sWorkOrderComments As String, sWorkOrderNumber As Integer,
sWorkOrderStatus As String)

On Error GoTo Err_SendEmail

'Check to see if sending an email is enabled Dim sSendEmail As
String sSendEmail = DLookup("[ParameterValue]",
"sys_SystemParameters", "[ParameterID] = 2")

If (sSendEmail = 1) Then
outText = "A NEW WORK ORDER WAS JUST CREATED IN THE SYSTEM" &
vbCrLf & vbCrLf outText = outText & "Client: " & sClient &
vbCrLf outText = outText & "Date Needed: " & sDateRequested &
vbCrLf outText = outText & "Description: " & sWorkOrderComments
& vbCrLf

toList = sRetreiveEmails Esubject = "RSED: (" & sWorkOrderNumber
& ") " & sWorkOrderStatus & " - " & sClient

DoCmd.SendObject acSendNoObject, , acFormatTXT, toList, ccList,
, Esubject, outText, True
End If

Exit_SendEmail:
Exit Function

Err_SendEmail:
MsgBox Err.Description Resume Exit_SendEmail

End Function



I have this within a module because I call it from several places with
the db, but if a user closes the outlook window, it gives me the
SendObject action error.

Is there a problem with error hanlding within modules? Anyway I can
prevent this message in the event the user decides not to send the
email?

Thanks
 
R

Rick Brandt

scadav said:
Within a module, I have the following:



Public Function SendEmail(sClient As String, sDateRequested As String,
sWorkOrderComments As String, sWorkOrderNumber As Integer,
sWorkOrderStatus As String)

On Error GoTo Err_SendEmail

'Check to see if sending an email is enabled Dim sSendEmail As
String sSendEmail = DLookup("[ParameterValue]",
"sys_SystemParameters", "[ParameterID] = 2")

If (sSendEmail = 1) Then
outText = "A NEW WORK ORDER WAS JUST CREATED IN THE SYSTEM" &
vbCrLf & vbCrLf outText = outText & "Client: " & sClient &
vbCrLf outText = outText & "Date Needed: " & sDateRequested &
vbCrLf outText = outText & "Description: " & sWorkOrderComments
& vbCrLf

toList = sRetreiveEmails Esubject = "RSED: (" & sWorkOrderNumber
& ") " & sWorkOrderStatus & " - " & sClient

DoCmd.SendObject acSendNoObject, , acFormatTXT, toList, ccList,
, Esubject, outText, True
End If

Exit_SendEmail:
Exit Function

Err_SendEmail:
MsgBox Err.Description Resume Exit_SendEmail

End Function



I have this within a module because I call it from several places with
the db, but if a user closes the outlook window, it gives me the
SendObject action error.

Is there a problem with error hanlding within modules? Anyway I can
prevent this message in the event the user decides not to send the
email?

Thanks

When the user cancels any action initiated with DoCmd that IS considered an
error by the calling code. Your error handler needs to check for the error
number and ignore error number 2501.
 
S

scadav

When the user cancels any action initiated with DoCmd that IS
considered an error by the calling code. Your error handler needs to
check for the error number and ignore error number 2501.

I added and still having a problem....


=========================================================================
Public Function SendEmail(sClient As String, sDateRequested As String,
sWorkOrderComments As String, sWorkOrderNumber As Integer,
sWorkOrderStatus As String) On Error GoTo Err_SendEmail

'Check to see if sending an email is enabled
Dim sSendEmail As String
sSendEmail = DLookup("[ParameterValue]", "sys_SystemParameters",
"[ParameterID] = 2")

If (sSendEmail = 1) Then
outText = "A NEW WORK ORDER WAS JUST CREATED IN THE SYSTEM" &
vbCrLf & vbCrLf outText = outText & "Client: " & sClient &
vbCrLf outText = outText & "Date Needed: " & sDateRequested &
vbCrLf outText = outText & "Description: " & sWorkOrderComments
& vbCrLf

toList = sRetreiveEmails
Esubject = "RSED: (" & sWorkOrderNumber & ") " &
sWorkOrderStatus & " - " & sClient

DoCmd.SendObject acSendNoObject, , acFormatTXT, toList, ccList,
, Esubject, outText, True
End If

Exit_SendEmail:
Exit Function

Err_SendEmail:
If Err.Number = 2501 Then
MsgBox "Cancelled"
Else
MsgBox Err.Description
End If

Resume Exit_SendEmail

End Function
=========================================================================


Am I doing something wrong with the error handling??? Any help would be
appreciated.
 
S

scadav

And what is the problem exactly? The same one as before? Do you not
get your "Cancelled" message?

Correct. I get the SendOBject action error [End] or [Debug]

Interesting part is that if I copy this code into the form code section, it
works properly. That is why I was curious if it was part of a module that
error handling doesn't work?!?!?!
 
S

scadav

That worked!!!! Thank you.

Does that affect any of the other handling that I have in place? Probably
should retest all of that?
 
R

Rick Brandt

scadav said:
That worked!!!! Thank you.

Does that affect any of the other handling that I have in place? Probably
should retest all of that?

Yes, but only in a way that you should want. The setting you had before was
saying "always break, even if I have code to handle the error". I honestly
don't know why anyone would ever want such a setting except perhaps for
debugging.
 
Top