Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need an easy way to print my MSFlexGrid in VB6

Posted on 2014-11-17
9
Medium Priority
?
401 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

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

Accepted Solution

by:
Dany Balian earned 1500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

927 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