Error Handling - Call another Function

  • Thread starter Thread starter Jackson via AccessMonster.com
  • Start date Start date
J

Jackson via AccessMonster.com

Hi,

I have a module called SendTrades which first checks conditions to send an
email, if the conditions are satified, it calls another module, EmailTrades
which will then put together an email and send it off.

It then goes back to the SendTrades function which then launches an update
query which updates which records have been sent via email.

If my mailbox in Outlook is full, currently the email doesn't get sent but
since the error is in the called function the original SendTrades continues
and updates the records as sent. What I want to do is when EmailTrades faces
any sort of error emailing, it then passes back to SendTrades but at the
Error Handler line - is this possible?

Thanks.
 
You can return a boolean from the EmailTrades function to indicate whther it
was successful. For example:

Private Sub SendTrades()
On Error GoTo Err_Handler
'do some stuff
If EmailTrades(parameters) Then
'Do more stuff....
Else
MsgBox "Problem with the email"
End If

Err_Resume:
Exit Sub
Err_Handler:
MsgBox Err.Description
Resume Err_Resume
End Sub

Public Function EmailTrades(ByVal parameters as blah) As Boolean
On Error GoTo Err_Handler
'do some emailing stuff. If it fails here, the function will return false.
EmailTrades = True

Err_Resume:
Exit Function
Err_Handler:
Resume Err_Resume
End Function

Barry
 
Back
Top