Search code examples
vbams-accessms-access-reports

How to stop DoCmd.OutputTo from printing file?


I have created report in MS Access and an on_click command to save the mentioned report as a PDF on the user's desktop.

The problem is that after running this command not only save PDF version, but also prints it.

I am confused, which part of my code gives command to print whole thing?

Private Sub Oldsys_atask_isorei_Click()
    'file name
    ReportName = "Report_" & Format(Now, "_yyyy-mm-dd") & ".pdf"
    'path to Users desktop
    DTAddress = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "/"

    'opens report in background (without it OutputTo did not seemed to work)
    DoCmd.OpenReport "rprtOldsys_isorei", acViewNormal, , , acHidden
    'saves report in PDF on Users desktop
    DoCmd.OutputTo acOutputReport, "rprtOldsys_isorei", acFormatPDF, DTAddress & ReportName, True
    'closes opened report
    DoCmd.Close acReport, "rprtOldsys_isorei", acSaveNo
End Sub

Solution

  • acViewNormal means print this for a report, that's the default view.

    Either use acViewReport (report view) or acViewPreview (print preview) to not print the report.