我想打开一个打印对话框。我已经有十年没有在 VB 中编程了,而且我有点生疏了。
我得到了一个 MS Access VB 脚本的副本,它选择了一个 MDB 文件,然后只打印了一个副本。我的思考过程是:
- 打开一个对话框;
- 选择打印机;
- 输入份数;
- 打印。
目前,我要修改的原始脚本部分是:
[SQL query above this]
....
' Open form
Dim rs As DAO.Recordset
Set rs = db.OpenRecordset("select@@identity")
Debug.Print rs(0)
Dim q As String
q = "transfer_id=" & rs(0)
DoCmd.OpenForm "Transfer Report", acNormal, , q, ,acDialog
DoCmd.PrintOut
...
[End If, End Sub, etc.]
这只打印出一份报告,公司无法同时打印出其他副本。由于它在现场,他们无法使用复印机,但仍需要多份副本。
我找到的一个答案是 David-W-Fenton(谢谢!),它显示了如何创建一个对话框;以下脚本会完成我想做的事情吗?而且,如何在对话框中添加一部分以指定要打印的份数?
...
Dim varPrinter As Printer
Dim strRowsource As String
Dim q As String
Dim rs As DAO.Recordset
Set rs = db.OpenRecordset("select @@identity")
Debug.Print rs(0)
If Len(Me.OpenArgs) > 0 Then
q = Me.OpenArgs
Me.Tag = q
For Each varPrinter In Application.Printers
strRowsource = strRowsource & "; " & varPrinter.DeviceName
Next varPrinter
Me!cmbPrinter.RowSource = Mid(strRowsource, 3)
' first check to see that the report is still open
If (1 = SysCmd(acSysCmdGetObjectState, acReport, q)) Then
With Reports(q).Printer
Me!cmbPrinter = .DeviceName
Me!optLayout = .Orientation
End With
Me!txtPageTo = Reports(q).Pages
End If
End If
Public Function PrintReport(q As String) As Boolean
q = "transfer_id=" & rs(0)
' open report in PREVIEW mode but HIDDEN
DoCmd.OpenReport q, acViewPreview, , , acHidden
' open the dialog form to let the user choose printing options
DoCmd.OpenForm "dlgPrinter", , , , , acDialog, q
With Forms!dlgPrinter
If .Tag <> "Cancel" Then
Set Reports(q).Printer = Application.Printers((!cmbPrinter))
Reports(q).Printer.Orientation = !optLayout
Application.Echo False
DoCmd.SelectObject acReport, q
DoCmd.PrintOut acPages, !txtPageFrom, !txtPageTo
PrintReport = True
End If
End With
DoCmd.Close acForm, "dlgPrinter"
DoCmd.Close acReport, q
Application.Echo True
End Function