Solved

Need an easy way to print my MSFlexGrid in VB6

Posted on 2014-11-17
9
328 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
Industry Leaders: 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

Industry Leaders: 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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

756 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