Solved

Need an easy way to print my MSFlexGrid in VB6

Posted on 2014-11-17
9
269 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
  • 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
 

Author Comment

by:al4629740
ID: 40453986
not fully explained
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

757 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

22 Experts available now in Live!

Get 1:1 Help Now