Results 1 to 8 of 8
  1. #1
    Jerry Call is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    Champaign, Illinois
    Posts
    85

    VBA code to open a report, set to Landscape or Portrait, and set to Single or Duplex


    I have a command button which a user can use to print out a report.
    I understand the vba commands for opening, closing, PrintOut, etc.

    But I would also like to include vba code that sets the
    Landscape/Portrait options, and also the Single or Duplex options.
    And here I'm having a hard time sorting out the code.

    Could you get me to the relevant vba for these two options?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    you shoulnt needed it. the report is already set to either Land or Port by design.
    No need to change it.

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    See if this can help: Search Google Application.reports

    Code:
    Application.Reports(strDocName).Printer.Orientation = acPRORLandscape
    Application.Reports(strDocName).Printer.Orientation = acPRORPortrait
           
    Application.Reports(strDocName).Printer.Duplex = acPRDPSimplex
    Application.Reports(strDocName).Printer.Duplex = acPRDPHorizontal
    Application.Reports(strDocName).Printer.Duplex = acPRDPVertical

  4. #4
    Jerry Call is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    Champaign, Illinois
    Posts
    85
    Let me give you the code that runs when the user chooses the command button to run a typical report:

    Private Sub cmdSouthStoreSnacksTallySheet_Click()

  5. #5
    Jerry Call is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    Champaign, Illinois
    Posts
    85
    Messed up the previous message. Start over.
    Here's the code that runs when the user chooses the command button to run a typical report:
    Private Sub cmdSouthStoreSnacksTallySheet_Click()
    DoCmd.OpenReport "wksSouthStoreSnacksTally", acViewPreview
    DoCmd.PrintOut
    DoCmd.Close
    DoCmd.OpenForm "frmOpening", acNormal
    EndSub

    The difficulty is not so much with Portrait vs. Landscape printing.
    Rather, I want to be able to choose between Simplex and Duplex modes.
    That is, sometimes I want to print only one page on a side of a piece of paper;
    in other cases I want to print duplex, with the option of flipping or not flipping direction.
    Easy, of course, to choose these things if you bring up the printer control screen.
    But I want to do it in code within my app itself.

    So what code could I use to specify those options. What would it look like
    integrated into my code above?

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    I haven't messed with this for about 10 years, but
    off the top of my head, here's what I would try first.

    Code:
    Private Sub cmdSouthStoreSnacksTallySheet_Click()
    DoCmd.OpenReport "wksSouthStoreSnacksTally", acViewPreview
    If msgbox ("Do you want duplex?",vbyesno) = vbyes then
         Application.Reports("wksSouthStoreSnacksTally").Printer.Duplex = acPRDPHorizontal
    else
         Application.Reports("wksSouthStoreSnacksTally").Printer.Duplex = acPRDPSimplex
    end if
    DoCmd.PrintOut
    DoCmd.Close
    DoCmd.OpenForm "frmOpening", acNormal
    EndSub
    
    Last edited by davegri; 09-23-2021 at 06:57 PM. Reason: added else

  7. #7
    Jerry Call is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    May 2020
    Location
    Champaign, Illinois
    Posts
    85
    Works like a charm. Thanks so much. I know how to do these settings in the regular Access interface
    (although they're not very intuitive to get at), but I do appreciate having the vba version.

    Alas, I still can't find the place to click to automatically mark this thread as solved.

  8. #8
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    Works like a charm. Thanks so much. I know how to do these settings in the regular Access interface
    (although they're not very intuitive to get at), but I do appreciate having the vba version.

    Alas, I still can't find the place to click to automatically mark this thread as solved.
    Click image for larger version. 

Name:	solved.png 
Views:	11 
Size:	9.6 KB 
ID:	46278

    Glad it worked for you. I marked thread solved.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Duplex Printing for a Report
    By NewbyForAccess in forum Reports
    Replies: 0
    Last Post: 11-02-2018, 01:52 PM
  2. Open a Single record in a Report
    By Simonhtc4 in forum Reports
    Replies: 5
    Last Post: 05-25-2017, 11:22 AM
  3. Replies: 1
    Last Post: 11-24-2012, 04:40 PM
  4. Landscape Page header on a Report
    By Alan1 in forum Reports
    Replies: 2
    Last Post: 07-25-2011, 03:25 AM
  5. Automating changing Report Print Set-up to Landscape
    By Neil Bingham in forum Reports
    Replies: 0
    Last Post: 12-07-2009, 06:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums