Dim pageheader
Dim pagefooter
Dim pageleft
Dim pageright
Dim usewidth
Dim useheight
Dim i, j, k As Integer
Dim word As String
Dim startx
Dim starty
Dim startyline ‘ 用来纪录打印竖线的起点
一个例子
Private Sub Command1_Click()
' Use 1 inch margins.
Const TOP_MARGIN = 1440
Const LEFT_MARGIN = 1440
Dim bottom_margin As Single
Dim db As Database
Dim qdef As QueryDef
Dim rs As Recordset
Dim dbname As String
Dim the_year As Integer
Dim the_value As Integer
MousePointer = vbHourglass
DoEvents
' Open the database.
dbname = App.Path
If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
dbname = dbname & "data.mdb"
Set db = OpenDatabase(dbname)
' Get the records.
Set qdef = db.CreateQueryDef("", _
"SELECT Year, Value FROM YearlyValues")
Set rs = qdef.OpenRecordset(dbOpenSnapshot)
' Read the data and print it.
bottom_margin = Printer.ScaleTop + _
Printer.ScaleHeight - 1440
rs.MoveFirst
Printer.CurrentY = TOP_MARGIN
Do While Not rs.EOF
' Use rs!FieldName to get the data for
' the field named FieldName.
Printer.CurrentX = LEFT_MARGIN
Printer.Print _
Format$(rs!Year, "yyyy") & _
vbTab & _
Format$(rs!Value, "0.0000")
' See if we have filled the page.
If Printer.CurrentY >= bottom_margin Then
' Start a new page.
Printer.NewPage
Printer.CurrentY = TOP_MARGIN
End If