Hi everyone,
I have a peace of VBA code that used to work, but now doesn't. Here is the code:
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "DT14_IQOQdoc", acViewPreview, WhereCondition:="[Doc ID]=" & Me![Doc ID]
DoCmd.OutputTo acOutputReport, "DT14_IQOQdoc", acFormatPDF, CurrentProject.Path & "\Current Reports\" & Me![CustDoc] & " - " & Me![Document Type] & " - " & Me![DocDate] & " - " & Me![Bath Model] & " - " & Me![Bath SN] & ".pdf"
DoCmd.Close acReport, "DT14_IQOQdoc"
The issue is this - when the code is run (via a button), the record is saved, the report opens in print preview, filters to the correct record and is complete and correct, but it will not then save as a PDF. The printing dialogue window appears, and the correct directory and file name are ready to go...but it then immediately disappears and doesn't output the PDF. The report then remains open in print preview mode and doesn't close. I've checked individual parts of the code and each bit works. Form what I can tell, the issue arises between the report opening in print preview and then starting the output to PDF. I get no error messages, and as I said, the report opens correctly but then the whole process seems to just fail as soon as the output to PDF tries to begin.
Interestingly, if I manually open the report and print or export to PDF - this works fine.
Another interesting thing - if I alter the code to open the report and don't ask to filter a specific record, it works too and outputs a massive report with all records.
The report in question is 25 pages long, and contains a lot of individual points of data (300-400) from across 4-5 tables.
I also have a other similar reports that have less data points (200-300) but uses the exact same layout and pages etc. and these DO export to PDF when the code is run.
This code used to always work. But now doesn't and I can't seem to pinpoint the issue. Could this be a memory problem? Is the code running too quickly or has Access not got enough memory to output the larger reports to pdf in this way?
Any ideas are warmly welcome as to what is causing this!
I have a peace of VBA code that used to work, but now doesn't. Here is the code:
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "DT14_IQOQdoc", acViewPreview, WhereCondition:="[Doc ID]=" & Me![Doc ID]
DoCmd.OutputTo acOutputReport, "DT14_IQOQdoc", acFormatPDF, CurrentProject.Path & "\Current Reports\" & Me![CustDoc] & " - " & Me![Document Type] & " - " & Me![DocDate] & " - " & Me![Bath Model] & " - " & Me![Bath SN] & ".pdf"
DoCmd.Close acReport, "DT14_IQOQdoc"
The issue is this - when the code is run (via a button), the record is saved, the report opens in print preview, filters to the correct record and is complete and correct, but it will not then save as a PDF. The printing dialogue window appears, and the correct directory and file name are ready to go...but it then immediately disappears and doesn't output the PDF. The report then remains open in print preview mode and doesn't close. I've checked individual parts of the code and each bit works. Form what I can tell, the issue arises between the report opening in print preview and then starting the output to PDF. I get no error messages, and as I said, the report opens correctly but then the whole process seems to just fail as soon as the output to PDF tries to begin.
Interestingly, if I manually open the report and print or export to PDF - this works fine.
Another interesting thing - if I alter the code to open the report and don't ask to filter a specific record, it works too and outputs a massive report with all records.
The report in question is 25 pages long, and contains a lot of individual points of data (300-400) from across 4-5 tables.
I also have a other similar reports that have less data points (200-300) but uses the exact same layout and pages etc. and these DO export to PDF when the code is run.
This code used to always work. But now doesn't and I can't seem to pinpoint the issue. Could this be a memory problem? Is the code running too quickly or has Access not got enough memory to output the larger reports to pdf in this way?
Any ideas are warmly welcome as to what is causing this!