Results 1 to 13 of 13

Thread: Printing

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    104

    Printing

    Hi guys. I was just wondering if its possible to print a recordset with column lines and rows? Thanks in advance guys.
    Last edited by trex; Jun 8th, 2005 at 09:41 PM.

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

    Re: Printing

    Load the rs into a flexgrid (with the gridlines you want) along with colums headings, and then print the form that its on.

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Printing

    Quote Originally Posted by trex
    Hi guys. I was just wondering if its possible to print a recordset with column lines and rows? Thanks in advance guys.
    Yes it is possible.
    It may take time for me to write the code. But here is the general procedure to follow:

    1. Use the rs.GetString method to get it into a variable and finally write it to a CSV file.
    2. Open this CSV file in an Excel object and do the column formatting, column width, fonts etc. and then print it.

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

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

    Re: Printing

    That's an awful lot of work just to get gridlines, not to mention that it would requre the use of Excel.

  5. #5
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Printing

    Quote Originally Posted by dglienna
    Load the rs into a flexgrid (with the gridlines you want) along with colums headings, and then print the form that its on.
    Yea, you need excel...but your method prints a form. How evil. Plus...what happens if there are more records than you can fit on the page? Alas, when printing like this it does not print all rows from the flexgrid, just what you can see.

    Woka

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

    Re: Printing

    We have a general SUB to print a FLEX GRID - it analyzes the column widths...

    Then it looks at the printer. Checks if it would fit at font 8, font 10, landscape, portrait - sees if legal tray is available.

    Then asks the user what they want to do - print on legal - stuff like that.

    Then it simply loops through the rows and columns and with the PRINTER object and setting .CURRENTX/.CURRENTY it prints the grid.

    It's very easy to print lines with PRINTER object as well - using PRINTER.LINE (x,y) - look up the exact format of this in HELP...

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

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

    Re: Printing

    Hi guys. I was just wondering if its possible to print a recordset with column lines and rows?
    the answer to this is yes,

    there are several ways to do it including some of the ones mentioned above, and also 3rd party tools such as qprinter2 and preview. plus the MS datareport designer

    also you can just print to the printer the data and the lines, horizantal and vertical, so that you have control over your own code.

    most people will have their own preferences as to which they use

    pete

  8. #8
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Printing

    Sorry my bad, I should have explained more in my post.
    To carry on from the 2 above posts you can use the printer object.
    VB Code:
    1. Printer.Print "Woof"
    2. Printer.EndDoc
    should print "Woof" on a page
    You require something like:
    VB Code:
    1. Dim adoRec As Recordset
    2.    'create recordset from DB
    3.    With adoRec
    4.       Do While Not .EOF
    5.          Printer.Print .Fields("Username").Value
    6.          .MoveNext
    7.       Loop
    8.       .Close
    9.    End With
    10.    Set adoRec = Nothing
    11.    Printer.EndDoc
    This would print all usernames to a page.
    To print grid lines and different fonts etc then you will need to use code similar to the above, but a little more complicated.
    We had some code to print from a listview I think. This was in a job I had 4 years ago.
    I'll see if I can dig it out.

    Woka

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    104

    Re: Printing

    Hi. hmmm im sorry for this but whats csv file? and how do i print a flex grid without printing the form?

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Printing

    I use this (or a varation of this) when I need to print a Recordset. You can modify this to include your lines and whatever following szlamany's suggestion. I don't really care about lines as much as margins and different pages, but this should get you started. This assumes the recordset exists already.
    VB Code:
    1. Const TOP_MARGIN = 1440
    2. Const LEFT_MARGIN = 1440
    3. Dim BOTTOM_MARGIN As Single
    4.           BOTTOM_MARGIN = Printer.ScaleTop + Printer.ScaleHeight - 1440
    5.          AdoRs.MoveFirst
    6.          Printer.CurrentY = TOP_MARGIN
    7.            Do While Not AdoRs.EOF
    8.             Printer.CurrentX = LEFT_MARGIN
    9.             Printer.Print AdoRs!Field1 & vbTab & Rs!Field2
    10.                 ' See if we have filled the page.
    11.                 If Printer.CurrentY >= BOTTOM_MARGIN Then
    12.                     ' Start a new page.
    13.                     Printer.NewPage
    14.                     Printer.CurrentY = TOP_MARGIN
    15.                 End If
    16.             AdoRs.MoveNext
    17.            Loop
    18.     AdoRs.Close
    19.     Printer.EndDoc
    20.     Set AdoRs = Nothing

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

    Re: Printing

    Hack is printing one row at a time - with vbTab to move the columns into some kind of placement.

    We actually print each cell - one at a time - and increment .CURRENTX to move to the right for each cell.

    In order for automatic line advance to not occur - put a ; character at the end of the print statement - such as PRINTER.PRINT RS!COL;

    By setting the .CURRENTX/.CURRENTY ourselves it's quite easy to make sure that you have a TWIP position on the paper for the grid-lines to appear in.

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

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

    Re: Printing

    Quote Originally Posted by trex
    Hi. hmmm im sorry for this but whats csv file? and how do i print a flex grid without printing the form?
    .CSV is a file extension for a comma-separated file - one that's easy to import into EXCEL.

    I would recommend keeping away from EXCEL to perform this task - you will only be burned by it's poor formatting of dates and numeric values...

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

  13. #13
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Printing

    Quote Originally Posted by trex
    Hi. hmmm im sorry for this but whats csv file? and how do i print a flex grid without printing the form?
    CSV files are Comma Seperated Files and Excel recogizes it easily. But it was just an example. You may use tab seperated file or any other delimiter.

    Writing out a CSV file is easy:
    VB Code:
    1. Sub RecordsetToCSV(rs as ADODB.Recordset)
    2.     Dim m
    3.     rs.MoveFirst
    4.     m = rsurl.GetString(, , " , ", vbCrLf)
    5.     Open App.Path & "\MyFile.csv" For Output As #1
    6.     Print #1, m
    7.     Close #1
    8.     m = ""
    9. End Sub
    After this you may open this file in Excel and print it.

    Pradeep
    Last edited by Pradeep1210; Jun 9th, 2005 at 06:14 AM.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

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