Sub PrintRecordset(recRecordset as Recordset) Dim LeftMargin AsInteger Dim HeadTopPosition AsInteger Dim FieldNum AsInteger Dim PageCounter AsInteger Dim MyRecordset As Recordset Const FooterTopPosition=24
Set MyRecordset=recRecordset PageCounter =1 '设置Printer对象坐标的度量单位为厘米 Printer.ScaleMode = vbCentimeters
Printer.Font.Name ="Times New Roman" Printer.Font.Size =12
Printer.Print "Lovesoft Corp." Printer.Print ""
If MyRecordset.EOF And MyRecordset.BOF Then MsgBox"No Record At Presend!", vbCritical + vbOKOnly, "Print Error" ExitSub EndIf MyRecordset.MoveFirst
Do Until Printer.CurrentY > FooterTopPosition
'Print the fields of the recordset in sequence For FieldNum =0To MyRecordset.Fields.Count -1 Printer.Print MyRecordset.Fields (FieldNum).Name & _ ": "& _ MyRecordset.Fields(FieldNum).Value If Printer.CurrentY > FooterTopPosition Then Printer.CurrentX =8 Printer.Print "Page: "& PageCounter '创建多页文档 Printer.NewPage PageCounter = PageCounter +1 EndIf Next FieldNum
MyRecordset.MoveNext If MyRecordset.EOF ThenExitDo '在记录之间空一行 Printer.Print "" Loop
'Print the Page number as a footer Printer.CurrentX =8 Printer.CurrentY = FooterTopPosition Printer.Print "Page: "& PageCounter '将输出送到打印机 Printer.EndDoc End Sub