将打印按钮的单击事件代码如下书写:
On Error GoTo Err_Command27_Click
Dim stdocname As String, PrtName As String
Dim rpt As Report
Dim prt As Printer
stdocname = "rptSesldetails" '选择报表
PrtName = Me.strPrint.value '读出选择的打印机
Set prt = Application.Printers(PrtName) '将打印机对象设置为列表框中选择中的名字
prt.Orientation = acPRORLandscape '无论报表的页面设置是横向还是纵向,这句代码都将打印机的设置改为了横向
Reports(stdocname).Printer = prt '设置报表的打印机
DoCmd.OpenReport stdocname, acNormal '打印报表
Me.状态.Caption = "报表已经成功输入..."
Me.状态.ForeColor = 0
Exit_Command27_Click:
Exit Sub
Err_Command27_Click:
Me.状态.Caption = "请指定打印机后执行..."
Me.状态.ForeColor = 255
MsgBox Err.Description
Resume Exit_Command27_Click