Results 1 to 7 of 7
  1. #1
    AlexTheHelpful is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2019
    Posts
    4

    Macro for Table - Need to Print Landscape and in A3

    Good afternoon.

    This will be my first question on this forum so take it easy on me as I am a total MS Access muppet.

    I set up the following Macro with the idea being to automatically print a table out in Landscape A3:

    Open Table:
    • Name: Example
    • View: Datasheet
    • Data Mode: Read Only

    Runcode:
    • Public Function Landscape()

    Application.Printer.Orientation = acPRORLandscape
    End Function
    Runcode:



    • Public Function PageSize()

    Application.Printer.PaperSize = acPRPSA3
    End Function
    Runcode:

    • Public Function PrintDoc()

    DoCmd.Printout acPrintAll, , , acHigh
    End Function

    This does not appear to work though. Therefore could anyone advise what I should of done.

    Note: This was working fine previously so I know it can be done, I just can't remember how (a colleague overwrote the original macro, so the above is my attempt to recreate).

    If you need any additional information, please let me know.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    why do you need a macro for this. Just go to the design view of the report and change the orientation in the design of the report, save the changes, then you don't have to mess with it.

  3. #3
    AlexTheHelpful is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2019
    Posts
    4
    rpeare.

    Thank you for coming back to me.

    So to expand a bit more:
    > I want this "autoprint" button on a "HomePage" form, so that it automatically prints out for my users.
    > This is not a "Report" but a "Table" it is printing
    > At the moment (as an interim) it just opens the Table and puts it into "Print Preview". However I want it to Open the table, A3 and Landscape the print layout, print the table, and close the table all at once. It was working fine until it was overwritten, I just can't remember the code.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    "Does not work" means what - error message, wrong result, nothing happens?

    Why use macros if you have VBA code? The following worked for me, at least the output was landscape.

    Sub PrintTable()
    DoCmd.OpenTable "Rates", , acReadOnly
    Application.Printer.Orientation = acPRORLandscape
    Application.Printer.PaperSize = acPRPSA3
    DoCmd.PrintOut acPrintAll, , , acHigh
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    AlexTheHelpful is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2019
    Posts
    4
    Sorry. I hate it when someone says "Does not work" too. It basically said it couldn't find/run Landscape() (and the others too).

    However your code works like a charm - printed to A3 and in landscape. I now have two more favours regarding your code.

    Favour 1 - What would the code like for a line to automatically close the table (I assume something like DoCmd.CloseTable "Rates" at the end)?
    Favour 2 - How do I apply that VBA code to the button on the form?

    (Note: to apply the above I was going to Database tools, VBA, adding a module and writing the VBA code. Then clicking the desired button, going to event tab & on click, using Macro builder, using the default dropdown options for opening and closing the database, and the "Runcode" option for other 3 VBA functions. However now it is using Sub instead of Public FUnction, I cannot see it in Runcode. Do I need to use another option)?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    DoCmd.Close acTable, "Example", acSaveNo

    Options:

    1. select [Event Procedure] in event property then click ellipses (...) to go to VBA procedure then either copy/paste code or Call the public sub

    2. make it a Function instead of Sub since only Functions can be called by macros
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    AlexTheHelpful is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2019
    Posts
    4
    Thank you very much for all your help, that worked perfectly :-)

    P.S. Sorry for being so useless at Access, I am a total newbie to it

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

Similar Threads

  1. Macro to print a mailing label
    By AntnyBrusk in forum Macros
    Replies: 3
    Last Post: 06-23-2015, 10:07 AM
  2. Replies: 2
    Last Post: 02-07-2015, 04:30 PM
  3. Print Button with Landscape as Default
    By d-mcc56 in forum Forms
    Replies: 1
    Last Post: 11-17-2014, 01:29 PM
  4. How do you print a macro?
    By ChuckColeman1812 in forum Access
    Replies: 9
    Last Post: 07-21-2012, 09:00 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