Changing report/printer layout and margins via VBA code
Posted on 2005-04-15
I am currently working on an app (Using Access 2003) where I have a need to specify a printer for Reports and a printer for Labels. The problem comes when I print a report then a label the labels margins and layout are different i.e. report layout is in Portrait and the labels need to be printed in Landscape. I have tried using the use specific printer and keeping the label printer set as the default in windows, but I am still having problems especially when using the runtime files.
Below is the code I am currently using;
'Create recordset for Printing.
Dim rstLocalInfo As DAO.Recordset
Set rstLocalInfo = CurrentDb.OpenRecordset("select [ReportPrinterName],[LabelPrinterName] FROM tblSiteInfo")
' Get the Printer object for the selected printer.
strTempPrinter = rstLocalInfo!LabelPrinterName
' get current default printer.
strDefaultPrinter = Application.Printer.DeviceName
' switch to printer of your choice:
Set Application.Printer = Application.Printers(strTempPrinter)
DoCmd.OpenReport "rptLabel", acViewNormal
'Swtich back to former default.
Set Application.Printer = Application.Printers(strDefaultPrinter)
Set rstLocalInfo = Nothing
I have found a couple of things out there but not sure how to tweak them to my needs.
Here is one of them;
Application.ActiveSheet.PageSetup.Orientation = xlLandscape
Any help is much appreciated