Solved

Need an easy way to print my MSFlexGrid in VB6

Posted on 2014-11-17
9
344 Views
Last Modified: 2014-12-04
I need an easy way to print my MSFlexGrid in VB6.  The problem with my present setup is that it is repeating the first row on every page when it prints the flexgrid.  I would simply like to print the grid with the headings.

Currently I am using this command

FlexGridPrint Me.MSFlexGrid1, , , , , 1

Open in new window

0
Comment
Question by:al4629740
[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
  • 5
  • 4
9 Comments
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40449170
where is the code for FlexGridPrint?

try this code: Print a FlexGrid control's data
0
 

Author Comment

by:al4629740
ID: 40451426
How would I call the routine?  Example please?
0
 

Author Comment

by:al4629740
ID: 40451437
Basically how would I execute this code:

Private Sub PrintFlexGrid(ByVal ptr As Object, ByVal flx As _
    MSFlexGrid, ByVal xmin As Single, ByVal ymin As Single)
Const GAP = 60

Dim xmax As Single
Dim ymax As Single
Dim X As Single
Dim c As Integer
Dim r As Integer

    With ptr.Font
        .Name = flxData.Font.Name
        .Size = flxData.Font.Size
    End With

    With flxData
        ' See how wide the whole thing is.
        xmax = xmin + GAP
        For c = 0 To .Cols - 1
            xmax = xmax + .ColWidth(c) + 2 * GAP
        Next c

        ' Print each row.
        ptr.CurrentY = ymin
        For r = 0 To .Rows - 1
            ' Draw a line above this row.
            If r > 0 Then ptr.Line (xmin, _
                ptr.CurrentY)-(xmax, ptr.CurrentY)
            ptr.CurrentY = ptr.CurrentY + GAP

            ' Print the entries on this row.
            X = xmin + GAP
            For c = 0 To .Cols - 1
                ptr.CurrentX = X
                ptr.Print BoundedText(ptr, .TextMatrix(r, _
                    c), .ColWidth(c));
                X = X + .ColWidth(c) + 2 * GAP
            Next c
            ptr.CurrentY = ptr.CurrentY + GAP

            ' Move to the next line.
            ptr.Print
        Next r
        ymax = ptr.CurrentY

        ' Draw a box around everything.
        ptr.Line (xmin, ymin)-(xmax, ymax), , B

        ' Draw lines between the columns.
        X = xmin
        For c = 0 To .Cols - 2
            X = X + .ColWidth(c) + 2 * GAP
            ptr.Line (X, ymin)-(X, ymax)
        Next c
    End With
End Sub

' Truncate the string so it fits within the width.
Private Function BoundedText(ByVal ptr As Object, ByVal txt _
    As String, ByVal max_wid As Single) As String
    Do While ptr.TextWidth(txt) > max_wid
        txt = Left$(txt, Len(txt) - 1)
    Loop
    BoundedText = txt
End Function

Open in new window

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!

 

Author Comment

by:al4629740
ID: 40453986
not fully explained
0
 
LVL 11

Accepted Solution

by:
Dany Balian earned 500 total points
ID: 40454543
did you to the link i sent you? just download the full project from the link beneath the code.
and try the code.

in summary, you just call!
PrintFlexGrid(ByVal ptr As Object, ByVal flx As MSFlexGrid, ByVal xmin As Single, ByVal ymin As Single)
ptr is the object on which you want to print, it can be a formname or just type Printer if you want to send it to the default printer
PrintFlexGrid Printer, Me.MSFlexGrid1, 1440, 1440

Open in new window

0
 

Author Comment

by:al4629740
ID: 40455711
I did do that....  I get an "object required" error on this line:

    With ptr.Font
        .Name = flxData.Font.Name
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40480541
did it work? or you're still getting the error? i just noticed ur comment!
0
 

Author Comment

by:al4629740
ID: 40481102
I still get the same error
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40481431
can you show me the code that you used? i tried the same code on my pc, and it works perfectly!
please provide me with the code you're using! (if you modified it), if not, send me how you're calling the function
0

Featured Post

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!

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

738 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