Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MSHFlexGrid print rows

Posted on 2001-07-23
7
Medium Priority
?
4,056 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:Michel Sakr
[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:Michel Sakr
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 28

Accepted Solution

by:
iboutchkine earned 200 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:Michel Sakr
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

610 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