Click to See Complete Forum and Search --> : Printing a DataGrid


eldo
November 14th, 2000, 09:22 AM
Ok Last question,

What is the best method for printing the content of a datagrid control???

Thanks Chad

Iouri
November 14th, 2000, 11:14 AM
Private Sub Command1_Click()
Call GridPrint(DataGrid1)
End Sub

Public Sub GridPrint(gridQuery As DataGrid)
Dim I As Integer
Dim J As Integer
Dim PTab As Integer

For I = 0 To gridQuery.ApproxCount - 1
PTab = 20 'Set the first tab value
'This checks to see if a page break is needed

If Printer.CurrentY + Printer.TextHeight(gridQuery.Text) > Printer.ScaleHeight - 600 Then
Printer.NewPage
End If

On Error Resume Next
gridQuery.Row = I 'Set the active row
On Error GoTo 0

For J = 0 To gridQuery.Columns.Count - 1
gridQuery.Col = J 'Set the current column

'Send the field to the print line and add the tab.
'Notice the semicolon at the end of the line.

Printer.Print Trim$(gridQuery.Text); Tab(PTab);

PTab = PTab + 20 'Increment the tab value
Next

'After each column has printed to the print line

'a Printer.Print statement without a semicolon will
'will send the line to the printer and start a new
'one.
Printer.Print
Next
Printer.EndDoc
End Sub

Iouri Boutchkine
iboutchkine@hotmail.com