Results 1 to 40 of 46

Thread: Best way to print reports ??

Hybrid View

  1. #1

    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

  2. #2
    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

  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 ??

    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

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