Greetings!


anybody know how to print msflexgrid and the data contain in this flexgrid. I want to know how to print this flexgrid into my printer.


thank in advance.

You need to use reports like Datareport or Crustal report for reportin g purpose. That gives you better options like data foramtting etc.

I would also like to know if this can be done.

Regarding printing of msflexgrid and the data inside the cell address of grid it is possible to print. There is a source code for this syntax in this address: www.planet-source-code.com

You can print the msflexgrid and its data.

Just type the printing msflexgrid for search and Visual basic for language to search it faster..


Have a nice day!

This is the way how you can take out data from FlexGrid

For i = 0 To Form1.MSFlexGrid1.Col
    For j = 0 To Form1.MSFlexGrid1.Row
      Print Form1.MSFlexGrid1.TextMatrix(i, j)
    Next j
Next i

No, I would also like to know how to do that.

So far I used for printing lines statment:

Printer.Line ()-()

ok.


I get requests to print boxes around text.

it would take a lot of work to accomplish.

Let's try this code.. I've been using it and it works excellent!!

Private Sub cmdPrint_Click()
'Print the grid with the top row as a title row
    FlexGridPrint Me.Grd, , , , , 1
End Sub

And also this..

Function FlexGridPrint(Grd As MSFlexGrid, Optional lOrientation As Long = vbPRORPortrait, Optional ByVal lMaxRowsPerPage As Long = -1, Optional lTopBorder As Long = 1000, Optional lLeftBorder As Long = 1000, Optional lRowsToRepeat As Long = 0) As Boolean
    Dim lRowsPrinted As Long, lRowsPerPage As Long
    Dim lThisRow As Long, lNumRows As Long, lImageHeight As Long, lLastImageTop As Long
    Dim lPrinterPageHeight As Long, lPagesPrinted As Long, lHeadingHeight As Long
    
    On Error GoTo ErrFailed
    Grd.TopRow = 1
    lNumRows = Grd.Rows - 1
    lPrinterPageHeight = Printer.Height
    lRowsPerPage = lMaxRowsPerPage
    lRowsPrinted = lRowsToRepeat

    If lRowsToRepeat Then
        'Calculate the height of the heading row
        For lThisRow = 1 To lRowsToRepeat
            lHeadingHeight = lHeadingHeight + Grd.RowHeight(lThisRow)
        Next
    End If

    Do
        'Calculate the number of rows for this page
        lImageHeight = 0
        lRowsPerPage = 0
        'Setup printer
        Printer.Orientation = lOrientation

        For lThisRow = lRowsPrinted To lNumRows
            lImageHeight = lImageHeight + Grd.RowHeight(lThisRow)
            If lRowsPerPage > lMaxRowsPerPage And lMaxRowsPerPage <> -1 Then
                'Image has required number of rows, subtract height of current row
                lImageHeight = lImageHeight - Grd.RowHeight(lThisRow)
                Exit For
            ElseIf lImageHeight + lTopBorder * 2 + lHeadingHeight > lPrinterPageHeight Then           'Allow the same border at the bottom and top
                'Image is larger than page, subtract height of current row
                lImageHeight = lImageHeight - Grd.RowHeight(lThisRow)
                Exit For
            End If
            lRowsPerPage = lRowsPerPage + 1
        Next
        
        'Print this page
        lPagesPrinted = lPagesPrinted + 1
        If lRowsToRepeat Then
            'Print heading rows
            Printer.PaintPicture Grd.Picture, lLeftBorder, lTopBorder, , lHeadingHeight, , 0, , lHeadingHeight
            'Print data rows
            Printer.PaintPicture Grd.Picture, lLeftBorder, lTopBorder + lHeadingHeight, , lImageHeight + lHeadingHeight, , lLastImageTop + lHeadingHeight, , lImageHeight + lHeadingHeight
        Else
            'Print data rows
            Printer.PaintPicture Grd.Picture, lLeftBorder, lTopBorder, , lImageHeight, , lLastImageTop, , lImageHeight
        End If
        
        Printer.EndDoc
        
        'Store printer position
        lRowsPrinted = lRowsPrinted + lRowsPerPage
        lLastImageTop = lLastImageTop + lImageHeight + lHeadingHeight
    
    Loop While lRowsPrinted < lNumRows
    
    FlexGridPrint = True
    
    Exit Function
    
ErrFailed:
    'Failed to print grid
    FlexGridPrint = False
    Debug.Print "Error in FlexGridPrint: " & Err.Description

End Function
This article has been dead for over six months. Start a new discussion instead.