Page 1 of 2 12 LastLast
Results 1 to 40 of 46

Thread: Best way to print reports ??

  1. #1

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Best way to print reports ??

    OK these are my current options..

    1. Use the microsoft WYSIYWIG code to print the contents of a Rich text box. But I am not sure if this code will print an embedded picturebox. I want to add graphs to my final report you see.

    2. Build up my reports from scratch. I really need the report to look as if it was a flexigrid type as I need to colour some cells to provide differentiation.

    3. Use a word doc saved as a .rtf, superimpose my data in the template,then use the RTB WYSIWYG print technique - see 1.

    4. Write the report directly using the Print object, handling width and page formatting by myself.

    5. Use the qPrinter class. Here a lot of the work apears top be done for me, but it means learning how to get the best from a third party class.

    6. ??? Idea's anyone.

    Whichever technique I eventually use I need to be able to display vertical text in the header area of the final report. This will require some alignment of individual picture box's with the vertical text within them.

    I have posted this conundrum as I am not sure where best to invest my time. I would be gratefull for any views or suggestions that you guys may have on this.

    TIA
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Best way to print reports ??

    my personal choice is to write to the printer object......... do all my own formatting and positioning, this take some time to setup, but i still prefer it

    for testing the printing (for speed and to save reams of paper) i found i could print to a mdi child form by setting it as an object and used the same code as i would to the printer, only difference in code was .show or .enddoc, but i just error handled to suit

    pete

  3. #3

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    Thanks for that Pete.

    Have you tried printing to virtual PDF printer and using a PDF viewer as an alternative method to saving paper. PDF995 do a free one.

    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Best way to print reports ??

    yes i have been using cutepdf to do the same thing, but it is still much slower than what i started doing last time, and don't get a filename dialog as well and then have to open the file in acrobatviewer to see.

    the form displays on screen very fast, and i only have to select which object i am printing to, so it doesn't take much to do.

    pete

  5. #5

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    Are you using the form as a print preview then ?
    Last edited by David.Poundall; May 7th, 2005 at 07:49 AM. Reason: typo
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Best way to print reports ??

    yes it would work as that, but doesn't have many features as other previews

    pete

    maybe i will develop it more at some time
    Last edited by westconn1; May 7th, 2005 at 11:00 AM.

  7. #7

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    When you do - don't forget to put it in the codebank
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  8. #8

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    Bump
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  9. #9
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Best way to print reports ??

    We use the PRINTER object directly.

    We store "report objects" in a table in SQL - and as we grab each recordset, we loop through the "report objects" to process the recordset.

    Here are the "report objects" we support.

    Code:
        ' 1     Font
        ' 2     Fontsize
        ' 3     FontBold=True
        ' 4     FontBold=False
        ' 5     FontItalic=True
        ' 6     FontItalic=False
        ' 7     Forecolor
        ' 10    Portrait
        ' 11    Landscape
        ' 12    Duplex (horizontal)
        ' 13    Paperpin
        ' 14    Papersize
        ' 20    Skip to line
        ' 21    Skip to next line
        ' 22    Header Control
        ' 23    Skip to right
        ' 24    Eject page
        ' 25    Break column
        ' 26    Specific column
        ' 27    Skip back to prior line
        ' 30    Date
        ' 31    Draw line
        ' 32    Draw left/right edge lines
        ' 33    Page
        ' 34    Query line
        ' 35    JPG
        ' 36    Draw Box
        ' 37    Vertical Print
        ' 40    Item with CR
        ' 41    Item without CR
        ' 50    Column with CR
        ' 51    Column without CR
        ' 52    Column (first-name-first) with CR
        ' 53    Column (if-not-blank) with CR
        ' 54    Column (numeric) with CR
        ' 55    Column (numeric) without CR
        ' 56    Column (numeric-nz) with CR
        ' 57    Column (numeric-nz) without CR
        ' 58    Total with CR
        ' 60    Paragraph
        ' 61    Paragraph (next 255 characters of text)
        ' 62    Load Key Column Data
        ' 63    Dump Key Column Data
        ' 64    Clear Key Column Data
        ' 70    If
        ' 71    End if
        ' 72    If-Break Area
        ' 73    End if-Break Area
        ' 74    Sub-Heading
        ' 75    End Sub-Heading
        ' 80    Sub report
        ' 81    End Sub report
        ' 82    Sub report RS loop start
        ' 83    Sub report RS loop end
        ' 100   Output column to text file
    In this we support vertical print on a page - here's a snippet of code from that section...

    Code:
    Dim VertFont As LogFont
    Dim lngPrevFont As Long, lnghFont As Long, lngRet As Long
    Code:
    Case 37
    
    Debug.Print "   PrintReport>"; i; ") x="; objPrt.CurrentX; " y="; objPrt.CurrentY _
                                                ; "  Vertical Print" _
                                                ; "  tab("; prtItems(i, 2) _
                                                ; ") strRS("; prtItems(i, 3) _
                                                ; ") Y Pos="; prtItems(i, 4) _
                                                ; ") Width= "; prtItems(i, 5) _
                                                ; ") Height="; prtItems(i, 6)
    lngHoldX = objPrt.CurrentX
    lngHoldY = objPrt.CurrentY
    
    f.picRotate.Cls
    f.picRotate.BackColor = vbWhite
    
    VertFont.lfEscapement = 2700    ' 180-degree rotation
    VertFont.lfFaceName = objPrt.Font & Chr$(0) 'Null character at end
    ' Windows expects the font size to be in pixels and to be negative if you are specifying the character height you want.
    VertFont.lfHeight = (objPrt.FontSize * -20) / Screen.TwipsPerPixelY
    VertFont.lfWeight = 700
    lnghFont = CreateFontIndirect(VertFont)
    lngPrevFont = SelectObject(f.picRotate.hDC, lnghFont)
    
    s3 = strRS(prtItems(i, 3), lngRS)
    f.picRotate.CurrentX = objPrt.FontSize * 20 * 1.2
    f.picRotate.CurrentY = 0
    f.picRotate.Width = prtItems(i, 5)
    f.picRotate.Height = prtItems(i, 6)
    f.picRotate.Print s3;
    
    objPrt.PaintPicture f.picRotate.Image, lngOffsetX + prtItems(i, 2), prtItems(i, 4) ', f.picRotate.TextHeight(s3), f.picRotate.TextWidth(s3)
    
    lngRet = SelectObject(f.picRotate.hDC, lngPrevFont)
    lngRet = DeleteObject(lnghFont)
    
    objPrt.CurrentX = lngHoldX
    objPrt.CurrentY = lngHoldY
    The reason we have gone through all this trouble is that we can support absolutely anything our customers throw at us. Having our own report writer engine makes custom aspects a breeze.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Best way to print reports ??

    I use #1 and a version of #3. My rtf has an object that I paste an image into, and replace fields that I have in the rtf, like [001]. I use .Find to find [001] and then .select to replace it. All of the tags are embedded in a table, so that things look very nice.

    I use this method for half of the reports, and the printer object for the other half, as they are less complex.

  11. #11

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    Many thanks szlamany and dglienna. I know that both of you have contributed on these issues in the forum before and I reacall both of your techniques. Specifically ...

    I apreciate the snippets that you have posted szlamany as I know the bulk of your code is propriotory. That gives me a good pointer on what area's would need to be covered if I go for the Printer object aproach.

    I have tried the technique that you have mentioned dglienna. But the problem I have is that my report grid sizes are going to be dynamic. As I don't know the size of my table in advance I can't use the technique. I have checked out the generated RTF code from a word table and I don't want to have to go to the trouble of learning .rtf formatting.

    Perhaps we should begin a project to provide an open source class that we could all use that covers the list that szlamany has raised ??

    I am on a tight schedule at the moment so I am going to have to use a getaround or bodge for now, but would anyone be interested in contributing to such a project in the near future? PM me if you are interested in getting involved.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Best way to print reports ??

    Perhaps you could get your company to purchase a professional reporting software like Crystal Reports Developer version?
    I use CR and its so very versatile and has about every function that you could possibly need/want.

    Just a suggestion.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Best way to print reports ??

    The dymanic table size issue is the reason that I use the printer object. I tried to adjust the size of the table, and ran into problems. For one report, I printed onto a second page that filled up both pages, but for dynamic objects, I had to eliminate some of the things that I would have liked, to keep the reports in the same format type.
    I used to print lines using QB for DOS, and spent a long time getting things to print correctly for dynamic items. I was going to take this approch for this project, until I discovered that I could paste an image into the report, which looks a lot better than my line-sticks used to.

  14. #14
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Best way to print reports ??

    here is code to create easy (simple) print preview

    the program i used this on prints a full page .jpg with text positioned over it with precision, the idea is to be able to complete (fill in the boxes) scanned .jpg forms and print them
    the preview was only for my use during development

    in general section
    VB Code:
    1. Dim tbindex As Integer, vprinter As Object


    VB Code:
    1. Select Case Command1(Index).Caption
    2.  
    3.  
    4.     Case "Start"
    5.    
    6.       OpenFile "dc2.jpg"
    7.  
    8.     Case "Print"
    9.    
    10.         Dim p As Printer
    11.         For Each p In Printers
    12.             If p.DeviceName = "CutePDF Writer" Then Set Printer = p: Exit For
    13.         Next
    14.         Set vprinter = preview 'or p printer here
    15.         With vprinter 'preview
    16. '        .Move 0, 0, Screen.Width, Screen.Width / picbox.Width * picbox.Height
    17.         sm = Me.ScaleMode: psm = .ScaleMode
    18.         pw = .Width
    19.             .PaintPicture picbox.Picture, 0, 0, .Width, .Height, , , picbox.Width, picbox.Height
    20. '            .PaperSize = 9
    21.             .FontSize = 10
    22.             i1 = Round(picbox.Width / .Width, 2)
    23.             i2 = Round(picbox.Height / .Height, 2)
    24.             For i = 1 To Text1.Count - 1
    25.                 .CurrentX = 0: .CurrentY = 0
    26.                 .CurrentX = Text1(i).Left / i1: .CurrentY = (Text1(i).Top) / i2 ' - 50
    27.  
    28.                 vprinter.Print Text1(i)
    29.                
    30.             Next
    31.          on error reusme next
    32.         .Show
    33.         .EndDoc
    34.          on error goto 0
    35.         End With
    36.  
    37.             SendKeys "test1.pdf", True   'don't remember if this bit worked
    38.             SendKeys "{enter}", True     ' to complete dialog for cutepdf
    39.            
    40.            
    41.  
    42.         Exit Sub
    43.        
    44.        Printer.EndDoc
    45.        
    46.     End Select
    47. End Sub

    requires mdi "prprev" and child "preview"
    total code for mdi
    VB Code:
    1. Private Sub MDIForm_Load()
    2. Move 100, 100, Screen.Width - 200, Screen.Height * 0.8
    3.  
    4. End Sub

    code for child
    VB Code:
    1. Private Sub Form_Click()
    2. Unload Me
    3. Unload prprev
    4. End Sub
    5.  
    6. Private Sub Form_Load()
    7. '       Move 0, 0, Screen.Width, Screen.Width / Form1.picbox.Width * Form1.picbox.Height
    8.        Move 0, 0, Screen.Width, Screen.Width / 8.5 * 11
    9.  
    10. 'Width = 8.5 * 567: Height = 11 * 567
    11. End Sub

    hope this is some use, if you develop it further, please let me know

    pete

  15. #15
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: Best way to print reports ??

    You probably know all this, but just in case -

    If you go down the 'use Printer object' path, then you just provide another form (does not need to be MDI), with a Picturebox on it.

    When creating your Subs for doing the printing, you pass in the object that the code is to 'print' to.
    If you pass in the Picturebox, then you get Print Preview.
    If you pass in the Printer, it prints.
    Practically all the printing commands are identical (Picturebox or Printer), and the Subs can test which it is sending to, for those few commands that differ.

    www.VB-Helper.com has lots of examples.

    EDIT Here's one -

    http://www.vb-helper.com/howto_print_preview.html

    If your graph needs anything special, Rod is very big on graphics stuff, so no doubt his site has what you need.

    I too have previously suggested that we get someting going on this site.
    Last edited by RobCrombie; May 7th, 2005 at 11:21 PM.
    Rob C

  16. #16
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Best way to print reports ??

    If szlammy posts his code, we'll convert it to Net for him

  17. #17
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Best way to print reports ??

    You probably know all this, but just in case -

    If you go down the 'use Printer object' path, then you just provide another form (does not need to be MDI), with a Picturebox on it.

    When creating your Subs for doing the printing, you pass in the object that the code is to 'print' to.
    If you pass in the Picturebox, then you get Print Preview.
    If you pass in the Printer, it prints.
    Practically all the printing commands are identical (Picturebox or Printer), and the Subs can test which it is sending to, for those few commands that differ.
    i prefer the mdi form as it automatically handles the scrolling etc, i print straight to the form, not a picbox, the whole thing was done for development as simplistically as possible, it works real good for what i want to do

    pete

  18. #18
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: Best way to print reports ??

    Two questions -

    I show all my Forms VBModal, and never use MDI forms.
    In the interests of simplicity, couldn't one use a Form, instead of a MDI form ?
    (IE would either do the same job, and the programmer can choose which to use ?)

    And how does using a form, handle scrolling better ?
    Rob C

  19. #19
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Best way to print reports ??

    rob,
    nothing to stop you doing that at all

    the reason i used mdi, (first time i had), as the form is to represent a letter or A4 size sheet it won't fit on screen, it was simple for me to let the mdi handle the scrolling of the child form, instead of either having to write the code to scroll a picbox (or similar) or to scale the printing

    pete

    if anyone wants the unfinished project to test the way i have it working, pm me

  20. #20

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    Perhaps you could get your company to purchase a professional reporting software like Crystal Reports Developer version?
    I use CR and its so very versatile and has about every function that you could possibly need/want.
    I am all for that so long as it works. I have not come across much good press for CR though. Are they the de-facto standard or are there other players out there.

    If szlammy posts his code, we'll convert it to Net for him
    Nice try.

    Thanks to you all for your feedback. I will leave the post open for now in case others can contribute as I still don't have an answer I can use. I will look into an off the shelf solution (as time is the problem not cost), and I will also look at mofdifying the qPrinter code (see first post) as it is so annoyingly close to what I need.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  21. #21
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Best way to print reports ??

    I looked at one of those tools, and it looked to me to be just as hard to learn their routine as it would to learn how to do it in rtf in the first place. I was going to do it all in Word, but didn't want to have to require word for my app.

    I think CR is an all around good product, and it is used by a LOT of people, it used to be given away back in the NT 3.5 days. I don't know anyone that actually bought a copy of it, though. I suppose they have improved it, but for the quick and dirty report, it works, and the people that I know that had it in 3.5 are still using it.

    The only bad press it's gotten is trying to deploy it from VB apps. If you use Inno, then it is pretty painless, from what I hear. Randem is around, and can help overcome most obstacles, as he developed Inno Script, and has some fine features in it.

  22. #22
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: Best way to print reports ??

    David P.
    Is paging required ?
    Is there NO grid on the Form ?
    Is it just a case of print what is on a Form (single page of paper) ?

    If the answer to all of those was yes (no paging, no grid, single sheet of paper), I have a suggestion
    Rob C

  23. #23

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    Inno is a superb app, and it is good to see Randem supporting it so well around the forum.

    I used crystal way back and found it's report setting up aproach (which was graphical) to be tedious and not well adapted to what I am trying to do. I would like to try it again in case they have changed it, but there is no download available from their site.

    I was tempted to learn .rtf as elsewhere in my app I have given it a try loading a rich text box, but too much to do there I feel.

    Writing my own driver for the printer object would be a good one - I like having low level control on my code. Probably comes from my early days as an assembler programmer - but it's time again.

    I think for now it loooks like I am going to bolt on a class to the qPrinter project. Edward Moth has a good preview control and low level building blocks that wrap some good low level functionality. If I bolt on my own class I can leverage Edwards work and contribute back to it.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  24. #24

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    Quote Originally Posted by RobCrombie
    David P.
    Is paging required ?
    Is there NO grid on the Form ?
    Is it just a case of print what is on a Form (single page of paper) ?

    If the answer to all of those was yes (no paging, no grid, single sheet of paper), I have a suggestion
    LOL - I wish. I need ....

    Yes to Paging
    Yes to Grid
    and the report is a composite and varies depending on user selections.

    But thanks for the thought
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  25. #25
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: Best way to print reports ??

    Have you considered automating Excel ?

    I have a very comprehensive form which displays a 'Job Register'
    It is wider than Texas, and may be longer than 'War and Peace'

    Printing that was going to be a nightmare.
    Instead I automated Excel and mimicked the grid (SGrid-2) into Excel.
    User loves it, and can use Excel's printing features (which he likes).
    Rob C

  26. #26

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    Instead I automated Excel and mimicked the grid (SGrid-2) into Excel.
    User loves it, and can use Excel's printing features (which he likes).
    I love that Idea Rob. I may not use it as the only way of doing it but I would certainly like to place it in my code as an option.

    The application is for teachers you see, and not all teachers like excell ( hence the reason for my app). Those teachers that did preffer excell would benefit from the functionality that automating it would give them.

    Given that I am also a major lover and user of SGrid and THAT is what I am trying to print out I would value any input you could give me.
    Last edited by David.Poundall; May 8th, 2005 at 03:33 AM. Reason: typo
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  27. #27
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: Best way to print reports ??

    Even the Teachers who don't like Excel, could be advised that they don't have to 'use Excel' in the true sense.
    Just introduce them to Excel's print facilities, and tell them it will be opened up for them, displaying the data, and all they have to do is go to the Print option. They can then print and get out.
    (Who knows it may even be possible to add a few more commands to the automation, and do that for them as well ?)

    I could send you my bas file, that is in the 'Job Register' project. However it is a bit specialised.
    Normally I develop a stand alone pgm to prove a concept, then incorporate it into my real project.
    If I did that, then I should send you that.
    a) Not sure if I did that
    b) I'm searching my drive now

    Worst case scenario, I will attach the one from my project.
    Last edited by RobCrombie; May 8th, 2005 at 04:18 AM.
    Rob C

  28. #28

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    That would be great - thanks Rob.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  29. #29
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: Best way to print reports ??

    This in a BAS file

    VB Code:
    1. Option Explicit
    2.  
    3. Private Const ROW_START As Long = 1
    4.  
    5. Public Sub ExportGrid(Grid As vbAcceleratorSGrid6.vbalGrid, ByVal bPrint As Boolean, Color_TOTAL_CELL_LIGHT As Long, Optional bUseCellValue As Boolean = False)
    6.    Dim lRow As Long
    7.    Dim lCol As Long
    8.    
    9.    Dim xlApp As Excel.Application
    10.    Dim xlSht As Excel.Worksheet
    11.    
    12.    Set xlApp = New Excel.Application
    13.    xlApp.Workbooks.Add
    14.    Set xlSht = xlApp.ActiveSheet
    15.    
    16.    ' Grid header-
    17.    For lCol = 1 To Grid.Columns
    18.       xlSht.Cells(ROW_START, lCol).Value = Grid.ColumnHeader(lCol)
    19.    Next
    20.    'Cell values
    21.    For lRow = 1 To Grid.Rows
    22.       For lCol = 1 To Grid.Columns
    23.         If bUseCellValue Then
    24.           xlSht.Cells(ROW_START + lRow, lCol).Value = Grid.CellItemData(lRow, lCol)
    25.         Else
    26.           xlSht.Cells(ROW_START + lRow, lCol).Value = Grid.CellText(lRow, lCol)
    27.         End If
    28.       Next
    29.    Next
    30.    ' Draw gridlines
    31.    xlApp.Range(xlApp.Cells(ROW_START, 1), xlApp.Cells(ROW_START + Grid.Rows, Grid.Columns)).Select
    32.    With xlApp.Selection
    33.       With .Borders(xlEdgeLeft)
    34.          .LineStyle = xlContinuous
    35.          .Weight = xlMedium
    36.          .ColorIndex = xlAutomatic
    37.       End With
    38.       With .Borders(xlEdgeTop)
    39.          .LineStyle = xlContinuous
    40.          .Weight = xlMedium
    41.          .ColorIndex = xlAutomatic
    42.       End With
    43.       With .Borders(xlEdgeBottom)
    44.          .LineStyle = xlContinuous
    45.          .Weight = xlMedium
    46.          .ColorIndex = xlAutomatic
    47.       End With
    48.       With .Borders(xlEdgeRight)
    49.          .LineStyle = xlContinuous
    50.          .Weight = xlMedium
    51.          .ColorIndex = xlAutomatic
    52.       End With
    53.       If Grid.Columns > 1 Then
    54.          With .Borders(xlInsideVertical)
    55.             .LineStyle = xlContinuous
    56.             .Weight = xlThin
    57.             .ColorIndex = xlAutomatic
    58.          End With
    59.       End If
    60.       With .Borders(xlInsideHorizontal)
    61.          .LineStyle = xlContinuous
    62.          .Weight = xlThin
    63.          .ColorIndex = xlAutomatic
    64.       End With
    65.    End With
    66.    
    67.    ' Highlight the header using the gray color
    68.    xlApp.Range(xlApp.Cells(ROW_START, 1), xlApp.Cells(ROW_START, Grid.Columns)).Select
    69.    xlApp.Selection.Font.Bold = True
    70.    With xlApp.Selection.Interior
    71.       .ColorIndex = 15
    72.    End With
    73.    
    74.    ' Highlight T O T A L S  line using the gray color
    75.   lRow = Grid.Rows  '<== Watch out as the excel row is 1 greater than the Grid Row
    76.   If Grid.RowItemData(lRow) = -999999999 Then
    77.     'Make the left cell font color white, also the right cell (it may be 0 wide, but who cares)
    78.     xlApp.Range(xlApp.Cells(lRow + 1, 1), xlApp.Cells(lRow + 1, 1)).Select
    79.     xlApp.Selection.Font.Color = RGB(255, 255, 255)
    80.     xlApp.Range(xlApp.Cells(lRow + 1, Grid.Columns), xlApp.Cells(lRow + 1, Grid.Columns)).Select
    81.     xlApp.Selection.Font.Color = RGB(255, 255, 255)
    82.     'Now cycle along the cells, setting to dark or light backcolor
    83.     For lCol = 1 To Grid.Columns
    84.       If Grid.CellBackColor(lRow, lCol) = Color_TOTAL_CELL_LIGHT Then
    85.         xlApp.Range(xlApp.Cells(lRow + 1, lCol), xlApp.Cells(lRow + 1, lCol)).Select
    86.         xlApp.Selection.Font.Bold = True
    87.         xlApp.Selection.Interior.ColorIndex = 24
    88.       Else
    89.         xlApp.Range(xlApp.Cells(lRow + 1, lCol), xlApp.Cells(lRow + 1, lCol)).Select
    90.         xlApp.Selection.Font.Bold = True
    91.         xlApp.Selection.Interior.ColorIndex = 23           '24
    92.       End If
    93.     Next lCol
    94.   End If
    95.  
    96. 'UNCOMMENT THE NEXT BLOCK TO SEE THE COLORINDEX COLORS
    97. '  ' Highlight a range with various ColorIndex values
    98. '  ' 15 = gray   24 = my light T O T A L S  color   23 or 55 my (very) dark T O T A L S  color
    99. '  Dim i As Integer
    100. '  For i = 1 To 56
    101. '    'xlApp.Range(xlApp.Cells(ROW_START + 1, 1), xlApp.Cells(Grid.Rows, Grid.Columns)).Select
    102. '    xlApp.Range(xlApp.Cells(ROW_START + 1, i), xlApp.Cells(ROW_START + 1, i)).Select
    103. '    xlApp.Selection.Font.Bold = True
    104. '    With xlApp.Selection.Interior
    105. '       .ColorIndex = i
    106. '       '.Color = RGB(220, 220, 220)  'I may have to set one of the 52 colors then use that
    107. '       '.pattern = xlPatternGray50 'xlPatternGray25 'xlSolid
    108. '    End With
    109. '  Next i
    110.    
    111.    'Size columns  and  rows
    112.    For lCol = 1 To Grid.Columns
    113.     If Grid.ColumnVisible(lCol) = True Then
    114.       xlApp.Columns(lCol).ColumnWidth = Grid.ColumnWidth(lCol) / 6
    115.     Else
    116.       xlApp.Columns(lCol).ColumnWidth = 0
    117.     End If
    118.    Next
    119.    
    120.    For lRow = 1 To Grid.Rows + 1
    121.     xlSht.Rows(lRow).RowHeight = 15
    122.    Next
    123.    
    124.    If bPrint Then
    125.       ' Print
    126.       xlApp.ActiveWindow.SelectedSheets.PrintOut
    127.       xlApp.ActiveWindow.Close SaveChanges:=False
    128.    Else
    129.       ' Displaying Excel
    130.       xlApp.Cells(1, 1).Select
    131.       xlApp.Visible = True
    132.    End If
    133.  
    134.     DoEvents
    135.     Set xlSht = Nothing
    136.     Set xlApp = Nothing
    137. End Sub
    138.  
    139. ' 1440 Twips  = 1 logical Inch
    140. '   72 Points = 1 logical Inch
    141. ' Convert my Pixels to Twips then * 72  and  / 1440
    142. Private Function ConvertPixelsToPoints(lIN As Long) As Long
    143.  Dim myLng As Long
    144.   myLng = lIN / 6
    145.   ConvertPixelsToPoints = myLng
    146. End Function
    Rob C

  30. #30

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    Thanks Rob - That is a great starting point for me.

    I would have posted you some points but the forum god says I have to spread a little around first

    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  31. #31

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    Ouch - tried to run the code and the first line got me. Until now I have not used automation and the followjng line kicks me out.

    Dim xlApp As Excel.Application

    Any idea as to what refs or component I need to load to get access to this object Rob?

    EDIT - Sorted
    Last edited by David.Poundall; May 8th, 2005 at 04:56 AM.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  32. #32
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: Best way to print reports ??

    I had posted a snapshot.
    Now un-posted, as I guess you figured it out it needed a reference to Say Excel 10
    Rob C

  33. #33

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    Yes - I found that I have 9 on my PC at the moment. I am still with Office 2000

    The reason I have never relied on Automation for anything before is that I didn't want to have to address M$ revision compatibility issues. Having said that if I use your code to add this as an optional feature then I get the best of both worlds

    I have just finished giving it a test run and apart from the fact that it loads Excell a little slow - it proves the point well, and I will definitely find a place for this in my code. Thank you for sharing.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  34. #34
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: Best way to print reports ??

    Thank you for sharing
    Thats ok.
    I have never relied on Automation for anything before is that I didn't want to have to address M$ revision compatibility issues
    This has been my first dabble also, as MS disregard for compatibilty alarms me.
    apart from the fact that it loads Excell a little slow
    There are two ways of doing this -
    Early binding, and late binding.
    One of those is a bit dependent on getting the correct reference (version of Excel), and one is is faster. Possibly the same one ?
    I don't know which is which, and I don't know which one we are using.
    I think we are using the 'I'll run with any version they've got' which I guess means late binding. and would be the slowest.
    But I am unsure.

    Any experts care to shed some light ?
    And which do they recommend ?
    Rob C

  35. #35

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    I will try exporting to .CSV and opening the .CSV with Excell. Then I can format using automation.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  36. #36
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Best way to print reports ??

    David,

    The logic to loop through an "array" of "report objects" and output data with the PRINTER object is really quite simple.

    And the powerful thing about this is that you only have "one report app" to support forever.

    We produce nearly 100 different reports with this single SUB at this point. For three distinct business lines.

    And there are no limitations - as you get with any off the shelf product.

    Here's a post from a couple of months ago about Crystal's limitations...

    http://www.vbforums.com/showpost.php...1&postcount=25

    So even though you say you are in a rush and need to produce this report now - do it with a loop and logic that you can use next time for your next report as well.

    Here's a SELECT off of the REPORT_T table from one of our databases.

    VB Code:
    1. RptSP      RptSeq      RptWhat     RptExtra1   RptExtra2   RptExtra3   RptExtra4   RptExtra5   RptText        
    2. ---------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------------
    3. rptGLTrial   1           10          0           0           0           0           0         NULL
    4. rptGLTrial   2           1           0           0           0           0           0         Times New Roman
    5. rptGLTrial   3           3           0           0           0           0           0         NULL
    6. rptGLTrial   4           2           10          0           0           0           0         NULL
    7. rptGLTrial   5           30          0           0           0           0           0         NULL
    8. rptGLTrial   6           2           17          0           0           0           0         NULL
    9. rptGLTrial   7           41          4900        0           0           0           0         GL Trial Balance
    10. rptGLTrial   8           2           10          0           0           0           0         NULL
    11. rptGLTrial   9           33          10500       0           0           0           0         NULL
    12. rptGLTrial   10          20          2           0           0           0           0         NULL
    13. rptGLTrial   11          41          5400        0           0           0           0         Town of Norwood
    14. rptGLTrial   12          20          4           0           0           0           0         NULL
    15. rptGLTrial   13          34          4750        0           0           0           0         NULL
    16. rptGLTrial   14          20          6           0           0           0           0         NULL
    17. rptGLTrial   22          4           0           0           0           0           0         NULL
    18. rptGLTrial   23          41          1000        0           0           0           0         Account
    19. rptGLTrial   24          41          2500        0           0           0           0         Description
    20. rptGLTrial   26          41          8000        0           0           0           0         Debit Amt
    21. rptGLTrial   27          40          10200       0           0           0           0         Credit Amt
    22. rptGLTrial   28          20          9           0           0           0           0         NULL
    23. rptGLTrial   29          31          11700       0           0           0           0         NULL
    24. rptGLTrial   30          22          60          0           0           0           0         NULL
    25. rptGLTrial   31          51          1000        0           0           0           0         NULL
    26. rptGLTrial   32          51          2500        1           0           0           0         NULL
    27. rptGLTrial   34          55          7500        2           16          1           0         NULL
    28. rptGLTrial   35          54          9700        3           16          1           0         NULL
    29.  
    30. (26 row(s) affected)

    rptSP = SPROC that will supply the RECORDSET for the report

    First object - rptWhat = 10 - landscape (see prior post for list of items).

    Next object - rptWhat = 1 - fontname, next = 3 - bold

    Next = 2 - fontsize - get that size from the RPTEXTRA1 column - size = 10

    To jump along - rptWhat = 41 - print text (GL Trial Balance) at twip position 4900

    An important one is in RPTSEQ 30 - the header control - rptWhat = 22.

    Basically what happens is for every row we grab from the recordset, we loop through this array.

    First time through every object gets processed - simple SELECT/CASE statement.

    Example of the CASE 1

    Code:
    Select Case prtItems(i, 1)
       Case 1
          Debug.Print "   PrintReport>"; i; ") x="; objPrt.CurrentX; " y="; objPrt.CurrentY _
                                          ; "  Font="; strItem(prtItems(i, 7))
          objPrt.Font = strItem(prtItems(i, 7))
    When we hit that HEADER CONTROL (rptWhat=22) spot we remember the "spot" itself and note the size of the page in print lines (60 in this example).

    Next row from the recordset - we loop through all the items again, but we skip sequence 1 through 30 because they are related to the "header".

    We only do 31 through 35 - printing the 4 columns of output from the recordset. They are columns 0, 1, 2 and 3. Columns 2 and 3 are numeric so we fit them to 16 digits and right justify. The 1 in RPTEXTRA4 for these report objects indicate they will be part of a grand total.

    We count the number of lines output - when we hit 60 we eject the page and reset the HEADER BOOLEAN variable so that the next row gets all array items processed for it.

    Like I said this is extremely simple BASIC code - nothing complex.

    And you don't want mine - it would be harder to understand then it's worth.

    Develop the report you have now with this basic concept. You will have less than 10 items in your SELECT/CASE statement and a simple loop.

    Next report you want to produce - use the same loop and enhance the "RPTWHAT" items as you need to support new features.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  37. #37

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    The main header text is straight forward to do so no problem there. What I really want to do is throw an array at the Printer Object and get it to work minimally with just that. OK the array is not just an array of numbers but it will be an array of types. Call it 'Cell' where ...

    VB Code:
    1. Type Cell
    2.   DisplayedValue as String
    3.   UnderlyingValue as Long    
    4.   Width as Long
    5.   Height as Long
    6.   IsAheader as Long
    7.   TextisVertical as Boolean     ' We could make it any angle later
    8.   BackColor as long           ' If no value it reverts to the default
    9.   ForeColor as long           ' If no value it reverts to the default
    10. End Type
    11. GridToDisplay() as Cell
    I already display my grid information from an underlying array and so all I need to do is pass the formatting of that array, and the data, over to 'GridToDisplay' and fire it at the Print Object - where hopefully all is taken care of for me.

    Hight and Width of the final grid will have to be properties that are set before the 'GridToDisplay' array is sent for printing. Also Portrait and Landscape will need to be determined in advance.

    I get the gist of where you are coming from with your report handler. I will be able to use that to control the type of report allocated to a specific area within my APP. Thank you for the insight.

    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  38. #38

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    Here's a post from a couple of months ago about Crystal's limitations...

    http://www.vbforums.com/showpost.ph...01&postcount=25
    Now that was an interesting link. I am glad I didn't part with any money.
    Last edited by David.Poundall; May 9th, 2005 at 01:34 PM.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  39. #39

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    Right ........ now its bugging me.

    It looks like it needs to be from the ground up so I am going to do a printer object so that I have maximum flexibility. I am not going to get into doing a print preview at this stage. I will bolt that code on later.

    So for now, in order that I get off on the right foot here, I would be most grateful for some considered opinions from my fellow coders on the following issues. In no particular order..

    1. Should the code be written as a single class module, a module or an Active X DLL.

    2. How should I handle next page?? Store all code for a page in one collection and all code for the second page in a second collection ??

    3. In the context of number 2, how would I handle widows and orphans.

    Some of you guys out there have already done this for yourselves. If the code is propriatry then just verbal pointers would do. At this stage code snippets may send me down a wrong line anyway.

    I already have code for doing graphs in picture boxes, so that's a straight feed into the printer object.

    FYI - the main thrust of going down this route is to be able to throw a Grid Array (with associated formatting information) at the printer code, and the code does a best fit into a specified rectangular space (including font scaling).

    As you can probably guess most of my app is grid based. Having said that I am still going to need wrappers for handling free text.

    Something like ...

    VB Code:
    1. Target.Print "This is the text to print", "Arial", eLeft, vbBlack, _
    2. Left, Top, LeftMargin, RightMargin
    if you get my drift.
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

  40. #40

    Thread Starter
    Frenzied Member David.Poundall's Avatar
    Join Date
    Sep 2002
    Location
    Robin Hood Land
    Posts
    1,457

    Re: Best way to print reports ??

    Add this question to the last few....

    What is the formula for font pitch in points to line spacing. Is there one ?
    David

    Learn the Rules so that you know how to break them properly.

    Printing dll dBTools MZTools Winsock API WinsockVB More Winsock SGrid2 MSChart Mail2Web

    If you have found this thread useful then read this

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width