Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.Close acreport causing "Illegal Operation" operation

Status
Not open for further replies.

Jackie

MIS
Feb 9, 2000
148
US
Is it illegal to include a Close command in the "Page" event?

The following code is used to execute a report that creates an .rtf file for each POC.

The first time the code is executed the code crashes on the
DoCmd.Close acReport, "POC_Project_Num" line. The Detail Window associated with this error states, "MSACCESS caused an invalid page default".

After I step through the code using the debug, the code cycles through, produces a separate report for each POC and does not crash.

Any help on this program would be greatly appreciated.

Private Sub Report_Page()

'Identify a variable to hold the report file name
Dim strReportName As String
Dim strDir As String
Dim strPOCName As String
Dim strDateMonth As String
Dim strDateDay As String
Dim strDateYear As String
Dim strDate As String

'Get the path for which to store the report
'Remember that the default directory must be set in Access via Options Menu

strDir = CurDir & "\POC_Proj_Num\"


'Create date for file name

strDateMonth = Format(Date, "mmm")
strDateDay = Format(Date, "d")
strDateYear = Format(Date, "yyyy")
strDate = strDateMonth & strDateDay & strDateYear

'Get POC name

strPOCName = Me!txt_POC

'Establish the report file name
strReportName = strDir & strPOCName & strDate & "." & "rtf"

'Save the report to a file
DoCmd.OutputTo acReport, "POC_Project_Num", "RichTextFormat(*.rtf)", strReportName


'Close the report to contine processing the remaining POC's reports
DoCmd.Close acReport, "POC_Project_Num"

End Sub
 
Jackie,

I do not believe you need to close the report each time, as you are outputting it and not opening it for preview/print.

I tested this out and it seems to work for me.

Good luck!
 
Thank you for your response.

When I commented out the DoCmd.close line, the report ran, but did not create individual reports for each POC.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top