Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2016
    Posts
    29
    Provided Answers: 1

    Unanswered: Exporting Forms to PDF in landscape using VBA

    Hi everyone,

    I'm looking to export a bunch of forms to PDF using VBA code on buttons (on each form). Some of the forms are better presented in landscape format, but I can't seem to find a working solution to changing the orientation of the PDF from Access. The only code I've found is

    Forms([Forms]![FRM_Main]![my_sub_frm].Form.Name).Printer.Orientation = acPRORLandscape
    DoCmd.PrintOut , 1, 1, acLow, 1, False

    Which I placed amongst the export code:

    MyFile = Format(Date, "yymmdd") & " - [xxx].pdf"
    Forms([Forms]![FRM_Main]![my_sub_frm].Form.Name).Printer.Orientation = acPRORLandscape
    DoCmd.PrintOut , 1, 1, acLow, 1, False
    DoCmd.OutputTo acOutputForm, [Forms]![FRM_Main]![my_sub_frm].Form.Name, acFormatPDF, "C:\[...]\" & MyFile, False

    This didn't work, I get the error 2450 - ... cannot find the referenced form ..., and I get the same error in whatever line order I order the code.

    Does anyone have an alternative solution which might work to rotate the tables when writing them to PDFs? There will be a dozen reports or so with each export, so I don't want the client to need to go through each one and rotate it manually. Thanks in advance.

  2. #2
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    630
    Provided Answers: 35
    use a report. Those you can customize.

  3. #3
    Join Date
    Nov 2016
    Posts
    29
    Provided Answers: 1
    Thanks, I'll give that a go

  4. #4
    Join Date
    Nov 2016
    Posts
    29
    Provided Answers: 1
    Is there a way to do that via VBA...? Looking online and the only solution I can find is to go to Save As -> Save Object As etc. If I'm going to build reports, I need the same functionality as previously, i.e. from a button on the form.. The only code I've found so far is:

    Dim rpt As Report
    Set rpt = CreateReport
    DoCmd.Restore

    Which just creates a blank report (even when the code is inside the form with the data). Is there not VBA code to create reports of the forms directly?

  5. #5
    weejas is offline Grumpy old man (training)
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    1,105
    Provided Answers: 18
    You can create reports with VBA, but it's a lot of work. It's much easier to create the relevant report in advance and use DoCmd.OpenReport to open it:
    https://msdn.microsoft.com/en-us/vba...-method-access
    10% of magic is knowing something that no-one else does. The rest is misdirection.
    Beers earned: 2

Tags for this Thread

Posting Permissions

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