Return without Gosub error

mafhobb

Registered User.
Local time
Today, 02:46
Joined
Feb 28, 2006
Messages
1,249
Hello.

I have a simple database with this code on a single button in the opening form
Code:
Private Sub cmdCreateSave_Click()
 
    DoCmd.OpenReport "Summary Report", acViewPreview, , , acHidden
 
    DoCmd.OutputTo acOutputReport, "Summary Report", acFormatRTF, "C:\Summary Report.rtf", , True
 
    DoCmd.Close acReport, "Summary Report", acSaveNo
 
    MsgBox "Report has been saved to the C: Drive"

End Sub

All this database does is open a report, which depends on a query, which asks the user for an input value (a number) to run the query.

The problem is...It is erratic. Some times it works and sometimes I get the message shown in the attached image: "the onclick event produces the error :return without GoSub"

If I click directly on the report (navigation window) the report opens fine. If I run the query directly, there are no problems. So the error is with this code.

If I run the code in the immediate window, everything is fine and the report gets saved.

Can anyone shade some light in this?

Thank you

mafhobb
 

Attachments

  • error.JPG
    error.JPG
    41 KB · Views: 250

Users who are viewing this thread

Back
Top Bottom