Please help...calling a function

E

erick-flores

Hello all

I am calling a the function "Sync" from my form. This is the code in
the form:

Private Sub Email_send_report_Click()

On Error GoTo Err_Email_send_report_Click

Call Sync <================CALLING THE FUNCTION
=============STOP CODE HERE IF ERROR ON FUNCTION=================
Dim stDocName As String

If MsgBox("message.", vbYesNo, "Submit Report?") = vbYes Then
Me.CHECK = True
Me.Dirty = False
stDocName = "Expense Report"
DoCmd.SendObject acReport, stDocName, "snapshot format"
DoCmd.Close
Else
'do nothing
End If

End Sub

What I want is, IF the function has an error then STOP THE REST OF THE
CODE OF THE FORM.

How do I do this??? Whats happening is, I dont want the e-mail to be
sent if one of the criterias under my function are not met. It is
giving the error (of the function) but it still running the e-mail
code in the Form.

Any ideas???

Thanks in advance
 
G

Guest

Hi Erick,

Have your function return a boolean value (true/false), have it return true
if it's successful, false otherwise. Then you can use your function thus:

if SYNC Then
' process your stuff

else
' error
msgbox "there was a sync error"

endif

Hope this helps.

Damian.
 
R

Rick Brandt

erick-flores said:
Hello all

I am calling a the function "Sync" from my form. This is the code in
the form:

Private Sub Email_send_report_Click()

On Error GoTo Err_Email_send_report_Click

Call Sync <================CALLING THE FUNCTION
=============STOP CODE HERE IF ERROR ON FUNCTION=================
Dim stDocName As String

If MsgBox("message.", vbYesNo, "Submit Report?") = vbYes Then
Me.CHECK = True
Me.Dirty = False
stDocName = "Expense Report"
DoCmd.SendObject acReport, stDocName, "snapshot format"
DoCmd.Close
Else
'do nothing
End If

End Sub

What I want is, IF the function has an error then STOP THE REST OF THE
CODE OF THE FORM.

How do I do this??? Whats happening is, I dont want the e-mail to be
sent if one of the criterias under my function are not met. It is
giving the error (of the function) but it still running the e-mail
code in the Form.

Any ideas???

Thanks in advance

If you have an error handler in the Sync function then the error will be
"handled" and your calling code will consider everything to be okay.

You can either remove the error handler from the Sync function (which will cause
the error to bubble up to the calling code) or you can raise another error in
the error handler of Sync that will be seen by the calling code as an error.

Does Sync normally return a value? That might provide additionla ways to handle
the issue.
 
E

erick-flores

If you have an error handler in the Sync function then the error will be
"handled" and your calling code will consider everything to be okay.
Yes this is exactly whats happenin..
You can either remove the error handler from the Sync function (which will cause
the error to bubble up to the calling code) or you can raise another error in
the error handler of Sync that will be seen by the calling code as an error.
I removed the error handler fron the Sync function, and I am now
traping errors from the calling code to display the right MsgBox.
Thank you very much for your help
 

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