----下面是本人在给单位开发一个产品销售情况统计分析软件的过程中,使用Printer对象从Recordset对象的虚拟表中打印数据的通用代码:
SubPrintRecordset(recRecordsetasRecordset)
DimLeftMarginAsInteger
DimHeadTopPositionAsInteger
DimFieldNumAsInteger
DimPageCounterAsInteger
DimMyRecordsetAsRecordset
ConstFooterTopPosition=24
SetMyRecordset=recRecordset
PageCounter=1
设置Printer对象坐标的度量单位为厘米
Printer.ScaleMode=vbCentimeters
LeftMargin=1.5
HeadTopPosition=2
----定义打印页左上角的X坐标和Y坐标,通过改变ScaleLeft和ScaleTop的值,可改变打印页的左边距和上边距
Printer.ScaleLeft=-LeftMargin
Printer.ScaleTop=-HeadTopPosition
Printer.Font.Name="TimesNewRoman"
Printer.Font.Size=12
Printer.Print"LovesoftCorp."
Printer.Print""
IfMyRecordset.EOFAndMyRecordset.BOFThen
MsgBox"NoRecordAtPresend!",
vbCritical vbOKOnly,"PrintError"
ExitSub
EndIf
MyRecordset.MoveFirst
DoUntilPrinter.CurrentY>FooterTopPosition
Printthefieldsoftherecordsetinsequence
ForFieldNum=0ToMyRecordset.Fields.Count-1
Printer.PrintMyRecordset.Fields
(FieldNum).Name&_
":"&_
MyRecordset.Fields(FieldNum).Value
IfPrinter.CurrentY>FooterTopPositionThen
Printer.CurrentX=8
Printer.Print"Page:"&PageCounter
创建多页文档
Printer.NewPage
PageCounter=PageCounter 1
EndIf
NextFieldNum
MyRecordset.MoveNext
IfMyRecordset.EOFThenExitDo
在记录之间空一行
Printer.Print""
Loop
PrintthePagenumberasafooter
Printer.CurrentX=8
Printer.CurrentY=FooterTopPosition
Printer.Print"Page:"&PageCounter
将输出送到打印机
Printer.EndDoc
EndSub
----调用上述PrintRecordset通用过程相当方便,下面是通过cmdPrint按钮的Click事件进行调用的一个实例:
PrivateSubcmdPrint_Click()
PrintRecordsetData1.Recordset
EndSub->
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!


