View Full Version : Using VBA to print Duplex in Access 2007


VBABeginner
07-22-2010, 12:44 PM
I am new to this forum, and new to VBA programming in MS Access. I am trying to print a report in duplex without getting way over my head in complicated coding and not having much success. I have tried:

DoCmd.OpenReport strReport acViewPreview
DoCmd.RunCommand acCmdPrint

which works but isn't practical as users are printing entire books consisting of many reports and the dialogue box pops up for each report. I guess it could work if anyone knows how to supress it after the first time.

Alternatively, I have tried:

DoCmd.OpenReport strReport acViewDesign, , , acHidden
Application.Printer.Duplex = acPRDPVertical
DoCmd.OpenReport strReport acViewNormal

which seems like it SHOULD work, but doesn't.

I have read until I'm bleary-eyed...does anyone have any suggestions?

Thanks so much!

Trevor G
07-28-2010, 05:50 AM
Read this article from Microsoft it deals with the Duplex printing

http://support.microsoft.com/kb/284286

The code they mention is as follows:

Note Not all printers and printer drivers support the functionality in the following sample code.

Note In Microsoft Office Access 2007, you only have to replace the report name "Catalog" with an available report for the sample code..

Private Sub PrintCatalogReport()
Dim rpt As Report Application.Printer = Application.Printers(0) DoCmd.OpenReport "Catalog", acViewPreview, , , acHidden
Set rpt = Reports!Catalog
With rpt.Printer
.BottomMargin = 720
.Copies = 2
.Duplex = acPRDPVertical 'Double sided
.PaperBin = acPRBNLargeCapacity
End With
DoCmd.OpenReport "Catalog", acViewNormal
DoCmd.Close acReport, "Catalog", acSaveNo
Set Application.Printer = Nothing
End Sub

When the print job is completed, this code will clear out the current settings and reset the global Application.Printer object to the default application printer.