Print a report's first page only with docmd.OutputTo to pdf now that there are issues with docmd.PrintOut RRS feed

  • Question

  • A database has been using docmd.PrintOut to print to pdf for years, running on Windows XP and Access 2003 (the report's default printer was Acrobat). It now needs to run on Access 2016 and Windows 10, and as noted in this post a few weeks ago, PrintOut seems to have issues on Windows 10; the Copies parameter seems to be ignored, and I need that.


    Anyways I wrote a routine that loops for the number of copies needed and uses DoCmd.OutputTo to print to a pdf file. It works fine but DoCmd.OutputTo doesn't have a page range parameter, like PrintOut does, and I need control over that as well. I'm trying to find a way to limit the pdf file to just the first page of the report.

    What I thought would work would be to add an expression like

    Cancel = (Page > 1)

    to the report's Detail_Print event (and header footer print events as well). However all of the pages for the report end up in the pdf anyways; there is nothing on the page, the page is blank, but obviously I don't want a blank second page. What I find via debug is that the expression is evaluated correctly, or nearly so. For report that would normally have two pages, the Detail_Print event with this code

       Debug.Print "Page " & Page & " and is page greater than 1 " & CStr(Page > 1)


    Page 1 and is page greater than 1 False
    Page 1 and is page greater than 1 False
    Page 2 and is page greater than 1 True

    In any case, it's been long enough since I fiddled with report cancel events so that I don't understand why the 2nd page loses it's content (textboxes etc) but is still written to the file as a pdf. Anyone have a suggestion? If there is another way to solve the need that would be fine of course.

    • Edited by rusticloud Sunday, February 10, 2019 7:25 AM
    Sunday, February 10, 2019 2:46 AM

All replies

  • Do I understand correctly you want multiple identical copies of the same PDF (restricted to 1 page)?

    How about you print one using your old method, then use VBA's FileCopy function to create the copies?

    -Tom. Microsoft Access MVP

    Sunday, February 10, 2019 6:01 PM
  • Yes that's a correct understanding. With PrintOut, if the report has acrobat as it's default printer, a dialog opens and asks you for a file name. The user has been living with this for ages. There can be many files in one print operation, and having him have to name each file is a waste of his time. I want the file to go to disk with a name that is assigned by vba. This is a reason to step away from PrintOut in general. With OutputTo I can assign a file name. With reluctance I tried SendKeys to see if I could assign and save the file which the PrintOut dialog asked for a file name but wasn't successful with that.

    It is true that one could copy the pdf at the file level, and defeat the broken copies param for PrintOut, but for the reasons above it'd be better to not require the file name to be entered manually.

    I've spent a lot of time now trying to get some combination of cancel to the sections of the report and there always seems to be a blank 2nd page. My latest notion was to invoke Report_NoData True in the detail section when page > 1, and cancel the report in the no data event, but that didn't solve it.

    Sunday, February 10, 2019 6:27 PM
  • Still hoping for addtional ideas/approaches on this topic.
    Thursday, February 14, 2019 2:14 AM
  • What seems to be working is to create a generic host report that contains a page sized subreport control, and to open the host report with an OpenArgs of the report that I want only a single page of, and to load the report that is passed in with OpenArgs into the subreport on the host reports OnOpen event. I've set the subreport control to not allow growing, so that the host report stays at one page no matter how long the embedded subreport might want to be.
    Sunday, February 17, 2019 1:35 AM