Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2011
    Posts
    3

    Question Unanswered: Can you publish a report to PDF with a page range in code?

    Does anyone know if it's possible to publish an Access report to a PDF file by specifying a page range through code. I know I can publish the whole report to a PDF file using this command and I have that working:


    DoCmd.OutputTo Method
    The OutputTo method carries out the OutputTo action in Visual Basic.
    Syntax

    expression.OutputTo(ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart, TemplateFile, Encoding, OutputQuality)

    Unfortunately, I don't see a parameter to specify a page range even though through the UI of Access 2007 I can do it.

    If that's not possible does anyone have a recommendation of a good workaround? Here is the problem I want to solve...

    I have a report that lists all my data, but I want to send the last page of it to one person, the second from last page to another person and maybe a couple pages before that to a third person, etc... Ideally, I'd like a flexible solution that would allow me to easily say that one of these guys now needs 2 pages instead of just 1, etc. I'm trying to fully automate a process where I publish separate report files, create separate emails to each recipient and attach the correct report to each person's email and automatically send it out. I have everything figured out except this publishing part.

    I appreciate any assistance.

    thanks,
    Scott

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    dunno if you can so it directly however by chosing what records to report you should be able to get close to what you want.
    assuming that:-
    there's a fixed number of rows (of data) per page
    there's some form of sequence in the records

    so you could find the nth row and retrieve from that row + nrows per page for x pages

    the LIMIT clause is your matey here
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2011
    Posts
    3
    I don't know how easy that would be to work with for what I'm trying to do. Say I have 20 records per page and my report query has 200 records in it.

    I know I can say give me the top 20 records which would be fine for the first report I want to email to someone. But the second person I want to give a report of records 21-41 so how would I go about returning a range of rows that are now between records 21 and 41?

  4. #4
    Join Date
    Jul 2011
    Posts
    3
    In case anyone else has this issue I think I just found a better solution. While Access doesn't seem to allow you to specify a page range for publishing to PDF, Word does. So you can output your Access report to RTF for example and open that document in Word from within Access and publish it with Word.

    Here's some code from Word to do the publishing:
    Dim FirstPage As Integer
    Dim LastPage As Integer

    FirstPage = 1
    LastPage = 2

    ActiveDocument.ExportAsFixedFormat OutputFileName:= _
    "C:\Users\first.last\Documents\My Files\Projects\PrayerChain\TestRPT.pdf", _
    ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
    wdExportOptimizeForPrint, Range:=wdExportFromTo, From:=FirstPage, To:=LastPage, Item:= _
    wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
    CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
    BitmapMissingFonts:=True, UseISO19005_1:=False

    NOTE: for this to run you need to add a reference to Microsoft Word's Object Library.

    This works very well and is much less hassle than trying to limit report records multiple times.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •