Solved

MSHFlexGrid print rows

Posted on 2001-07-23
7
4,035 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

719 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