Solved

MSHFlexGrid print rows

Posted on 2001-07-23
7
4,018 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 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