Solved

MSHFlexGrid print rows

Posted on 2001-07-23
7
4,026 Views
Last Modified: 2007-11-27
Hi.. I have a flex grid.. I want to print all the rows the following code will print out only the first chounk of rows only:

Private Sub Command2_Click()
 Printer.Font = "VERDANA"
 Printer.Orientation = 2
 Printer.FontSize = 12
 Printer.FontBold = True
 Printer.Print Label1.Item(0).Caption
'For x = 1 To Int((Grid1.Rows - 1) / 30) + 1
'Grid1.?!! = x * 30
Printer.PaintPicture Grid1.Picture, 1, 1400
'Next x
Printer.EndDoc
End Sub

I've set a loop to check the rows count and print each chunk but I can't get the proprety to scroll to the last row of the first chunk.. if it's possible.. besides this method is inaccurate since more then 30 rows might be printed and reprinted on the other page.. is there a way to define how much rows to print?

I can use Crystal reports but I'm using VB6.. besides I need to do it using MSHFlex grid if possible..
0
Comment
Question by:Silvers5
7 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 6308631
>'Grid1.?!! = x * 30
Grid1.TopRow = x * 30
DoEvents
0
 
LVL 20

Author Comment

by:Silvers5
ID: 6308716
hmm.. it's not working.. i'll work on it tomorrow..
0
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 6308742
Hi,

Why not resize your grid to be large enough to display all records, then print that, then restore it to the old size?

Zaphod.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Accepted Solution

by:
iboutchkine earned 50 total points
ID: 6308790
Sub PrintMSFG(ByVal pHorizontal as Boolean)
    Dim i As Integer
    Dim iMaxRow As Integer
    Dim j As Integer
    Dim msfGrid As MSFlexGrid
    Dim iPage As Integer
    ' frmLoan.MSFlexGrid1 is an invisible msflexgrid
    ' used only for this routine
    ' put it where your want and reference it apropiately
   
    Set msfGrid = Me.MSFlexGrid1
    msfGrid.FixedCols = 0
    msfGrid.Clear

    If pHorizontal = True Then
        Printer.Orientation = vbPRORLandscape
        iMaxRow = 44
    Else
        Printer.Orientation = vbPRORPortrait
        iMaxRow = 57
    End If

    If msfg.Rows Mod iMaxRow = 0 Then
        iPage = msfg.Rows \ iMaxRow
    Else
        iPage = msfg.Rows \ iMaxRow + 1
    End If
    msfGrid.Rows = iMaxRow
    msfGrid.Cols = msfg.Cols


    For i = 0 To msfg.Cols - 1
        msfGrid.ColWidth(i) = msfg.ColWidth(i)
    Next
    Screen.MousePointer = vbHourglass

    If pHorizontal = True Then
        Printer.CurrentX = 10000
    Else
        Printer.CurrentX = 7000
    End If

    For i = 0 To msfg.Rows - 2 + iPage
        If i Mod iMaxRow = 0 And i > 0 Then
            With msfGrid
                .Row = 0
                .Col = 0
                .ColSel = 0
                .RowSel = 0
 
                If pHorizontal Then
                    Printer.PaintPicture .Picture, 20, 1250, 15000, 10350
                Else
                    Printer.PaintPicture .Picture, 20, 1250, 11400, 13950
                End If

            End With
            Printer.NewPage
            msfGrid.Clear


            For j = 0 To msfGrid.Cols - 1
                msfGrid.TextMatrix(0, j) = msfg.TextMatrix(0, j)
            Next
            If pHorizontal = True Then
                Printer.CurrentX = 10000
            Else
                Printer.CurrentX = 7000
            End If
            Printer.CurrentY = 0
            i = i + 1
        End If
        For j = 0 To msfGrid.Cols - 1
            msfGrid.TextMatrix(i Mod iMaxRow, j) = msfg.TextMatrix(i - i \ iMaxRow, j)
        Next
    Next


    With msfGrid
        .Row = 0
        .Col = 0
        .ColSel = 0
        .RowSel = 0
        If pHorizontal Then
            Printer.PaintPicture .Picture, 20, 1250, 15000, 10350
        Else
            Printer.PaintPicture .Picture, 20, 1250, 11400, 13950
        End If
    End With
    Printer.EndDoc
    Set msfGrid = Nothing
    Screen.MousePointer = vbDefault
End Sub



0
 
LVL 20

Author Comment

by:Silvers5
ID: 6311560
I've done it this way with an invisible flex grid..

Private Sub Command2_Click()
'Setting the Grids column widths and columns, rows numbers
GridX.Width = Grid1.Width
GridX.Rows = 29
GridX.Cols = Grid1.Cols
For Colz = 0 To Grid1.Cols - 1
GridX.ColWidth(Colz) = Grid1.ColWidth(Colz)
Next Colz
zxx = Int((Grid1.Rows - 1) / 30) + 1 'number of pages
For x = 1 To zxx 'loop thru pages
RowZ = 0 ' row of GridX
    For RowX = ((30 * x) - 30) To (30 * x) 'loop thru rows
        If RowX < Grid1.Rows Then ' check if the first grid got to its end
            GridX.Rows = RowZ + 1
            If GridX.Rows > 1 And x = 1 Then GridX.FixedRows = 1
                For ColX = 0 To (Grid1.Cols - 1) 'loop thru columns
                    If (ColX = Grid1.Cols - 1 Or ColX = Grid1.Cols - 2) And Grid1.Row <> 0 Then
                        GridX.TextMatrix(RowZ, ColX) = Left(Grid1.TextMatrix(RowX, ColX), 10)
                    Else
                        GridX.TextMatrix(RowZ, ColX) = Grid1.TextMatrix(RowX, ColX)
                    End If
                Next ColX
            RowZ = RowZ + 1
        End If
     Next RowX
'Print here
If RowZ > 0 Then
Printer.Font = "VERDANA"
Printer.Orientation = 2
Printer.FontSize = 12
Printer.FontBold = True
Printer.Print Label1.Item(0).Caption & "  (Page:" & x & " of " & zxx & ")"
Printer.PaintPicture GridX.Picture, 1, 1400
Printer.EndDoc
End If
Next x


End Sub
0
 

Expert Comment

by:BobNH
ID: 12065446
Re: 'I've done it this way with an invisible flex grid..' from Silvers5,
I modified his/her sample to work in my application. I do however have one problem.
My top row(fixed, database field names) only prints on my first page. Any ideas on how to print the top row on every page?

Thanks,
Bob
0
 

Expert Comment

by:BobNH
ID: 12075346
I have Solved the Haeder issue.

Bob
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question