在VBA中访问2007多个报表配置

时间:2015-09-14 19:59:59

标签: vba printing access-vba ms-access-2007

我目前正在编写一些代码,以便我可以使用两个不同的报告执行以下操作:

  • 最终用户输入报告参数范围的第一个和最后一个作业,然后单击按钮
  • 启动作业存储在本地,计算第一个和最后一个之间的差异,并启动Do ...循环语句(带计数器),直到计数器等于差异。

在循环期间,作业参数增加1(与计数器相同),并且将打印报告。

如果我已经把你弄糊涂了,这里有一些示例代码可以直观地解释我目前正在做的事情:

Dim NetJobVar As String
Dim counter As Long
NetJobVar = Me.ToJob - Me.FromJob
counter = 0

DoCmd.SetWarnings False
'Query to add first job parameter to local table
Me.JobStatus.Visible = True

Do
    Me.JobStatus.Caption = "Printing " & Me.FromJob + counter & "..."
    'Insert report code here
    'Query to add 1 onto Job stored in local table
    counter = counter + 1
Loop Until counter = NetJobVar + 1

Me.JobStatus.Visible = False

除了这个之外,我已经完成了所有计划...我想让两个不同的打印机配置窗口出现(比如当您强制报告在VBA /模块中打印时)在实际打印报告之前Do ...循环语句。否则,这可能会导致无数提示和非常不满意的最终用户......

我需要两个配置提示的原因是因为我们将作业打印到两个不同的托盘(两种不同颜色的纸张)。

我偶然发现了一些事情...... herehere已经有所帮助,但并未完全达到我想要完成的目标。

让我知道你们的想法!

1 个答案:

答案 0 :(得分:2)

考虑绕过打印配置对话框的任何需求。相反,请使用VBA的Printer对象自动选择打印机设置,包括OrientationPaperSizePaperBin(用于托盘)等。

以某种方式将以下脚本集成到您的循环中。我列出了PaperBin常量的详尽列表,供您决定将哪一批报告发送到彩色纸张的哪些托盘。如果您将相同的报告打印到不同的纸盘,只需添加行以选择新的纸盒并再次打印报告。

Dim rpt As Access.Report

'Open report with any filters
DoCmd.OpenReport "JobsReport", acPreview, , "Job=" & Me.FromJob + counter
Set rpt = Reports("JobsReport")

'Set the default printer's orientation to portrait/landscape
rpt.Printer.Orientation = acPRORPortrait

'Set the default printer's paper size to letter/legal/tabloid/A3/A4
rpt.Printer.PaperSize = acPRPSLetter

'FIRST TRAY ----------------------------------------------
'Set the default printer's paper bin
rpt.Printer.PaperBin = acPRBNUpper 

'Print Report
DoCmd.OpenReport "JobsReport"

'SECOND TRAY  ----------------------------------------------
'Set the default printer's paper bin
rpt.Printer.PaperBin = acPRBNLower 

'Print Report
DoCmd.OpenReport "JobsReport"

'Constants for PaperBin
'acPRBNUpper = 1  ' Use paper from the upper bin
'acPRBNLower = 2  ' Use paper from the lower bin
'acPRBNMiddle = 3  ' Use paper from the middle bin
'acPRBNManual = 4  ' Wait for manual insertion of each sheet of paper
'acPRBNEnvelope = 5  'Use envelopes from the envelope feeder
'acPRBNEnvManual = 6  ' Use envelopes from the envelope feeder, but wait for manual insertion
'acPRBNAuto = 7  '(Default) Use paper from the current default bin
'acPRBNTractor = 8  ' Use paper from the tractor feeder
'acPRBNSmallFmt = 9  ' Use paper from the small paper feeder
'acPRBNLargeFmt = 10  ' Use paper from the large paper bin
'acPRBNLargeCapacity = 11  ' Use paper from the large capacity feeder
'acPRBNCassette = 14  'Use paper from the attached cassette cartridge
'acPRBNFormSource = 15  ' Use paper from the forms bin

Set rpt = Nothing