Solved

MSHFlexGrid print rows

Posted on 2001-07-23
7
4,009 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
Comment Utility
>'Grid1.?!! = x * 30
Grid1.TopRow = x * 30
DoEvents
0
 
LVL 20

Author Comment

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

Expert Comment

by:Z_Beeblebrox
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 28

Accepted Solution

by:
iboutchkine earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I have Solved the Haeder issue.

Bob
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now