DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 13 of 13

Thread: print recordset

  1. #1
    Hian Chew Guest

    print recordset


    I have to print an ADO recordset.
    What is the efficient way to send the recordset to the printer?
    Seems like doing record iteration printing is very slow
    for large recordset. Can someone point me to the right direction?

    Hian Chew

  2. #2
    Filipo Novo Mór Guest

    Re: print recordset


    "Hian Chew" <hschew00@yahoo.com> wrote:
    >
    >I have to print an ADO recordset.
    >What is the efficient way to send the recordset to the printer?
    >Seems like doing record iteration printing is very slow
    >for large recordset. Can someone point me to the right direction?
    >
    >Hian Chew


    Hian,

    You can save the recordset content in a file and then print the file. You
    can do this using the Save method of the recordset object.

    Filipo



  3. #3
    Rohit Wason Guest

    Re: print recordset


    Hian,

    Try this:
    strString = rst.GetString columndelimeter:=vbTab, rowdelimeter:=vbCrLf

    This will store the whole recordset (text formatted) into a string.
    Then you can print this string using Word.Document OLE automation(thats quite
    handy):

    Dim app As Word.Application
    Dim doc As Word.Document

    set app = GetObject("Word.Application")
    Set doc = app.Documents.Add
    With doc
    .Content = strString
    .Printout
    End With

    Hope it helps
    Cheers
    Rohit

  4. #4
    Hian Chew Guest

    Re: print recordset


    If I use Save method of the recordset,
    How do I do the printing from file?

    Hian



    "Filipo Novo Mór" <fmor@terra.com.br> wrote:
    >
    >"Hian Chew" <hschew00@yahoo.com> wrote:
    >>
    >>I have to print an ADO recordset.
    >>What is the efficient way to send the recordset to the printer?
    >>Seems like doing record iteration printing is very slow
    >>for large recordset. Can someone point me to the right direction?
    >>
    >>Hian Chew

    >
    > Hian,
    >
    > You can save the recordset content in a file and then print the file.

    You
    >can do this using the Save method of the recordset object.
    >
    > Filipo
    >
    >



  5. #5
    Hian Chew Guest

    Re: print recordset


    Does this work ok on the computer where Word application is not installed?
    Do I have to set close or nothing on any of these object after use?

    Hian Chew

    "Rohit Wason" <rohitw@ggn.hcltech.com> wrote:
    >
    >Hian,
    >
    >Try this:
    >strString = rst.GetString columndelimeter:=vbTab, rowdelimeter:=vbCrLf
    >
    >This will store the whole recordset (text formatted) into a string.
    >Then you can print this string using Word.Document OLE automation(thats

    quite
    >handy):
    >
    >Dim app As Word.Application
    >Dim doc As Word.Document
    >
    >set app = GetObject("Word.Application")
    >Set doc = app.Documents.Add
    >With doc
    > .Content = strString
    > .Printout
    >End With
    >
    >Hope it helps
    >Cheers
    >Rohit



  6. #6
    Filipo Novo Mór Guest

    Re: print recordset



    Hi, Hian!

    The easiest way to do this is calling the wordpad (or other text editor
    you have installed) and open the text with it (You can use the Shell function).
    Otherwise, if you don't want to depend on external program, you can open
    the text in VB and print it line to line:

    ------------------------------------------
    Dim Arq As Integer
    Dim Line As String
    Arq = FreeFile
    open "c:\mytext.txt" for input as #Arq
    While Not Eof(Arq)
    Line Input #Arq, Line
    Printer.Print Line
    Wend
    Close (Arq)
    Printer.EndDoc
    ------------------------------------------

    I hope it helps!

    Filipo



    "Hian Chew" <hschew00@yahoo.com> wrote:
    >
    >If I use Save method of the recordset,
    >How do I do the printing from file?
    >
    >Hian
    >
    >
    >
    >"Filipo Novo Mór" <fmor@terra.com.br> wrote:
    >>
    >>"Hian Chew" <hschew00@yahoo.com> wrote:
    >>>
    >>>I have to print an ADO recordset.
    >>>What is the efficient way to send the recordset to the printer?
    >>>Seems like doing record iteration printing is very slow
    >>>for large recordset. Can someone point me to the right direction?
    >>>
    >>>Hian Chew

    >>
    >> Hian,
    >>
    >> You can save the recordset content in a file and then print the file.

    >You
    >>can do this using the Save method of the recordset object.
    >>
    >> Filipo
    >>
    >>

    >



  7. #7
    Rohit Wason Guest

    Re: print recordset


    Hian,

    >Does this work ok on the computer where Word application is not installed?


    No this doesn't work without Word.

    >Do I have to set close or nothing on any of these object after use?


    Document.Close (False)


    Cheers,
    Rohit

    >
    >Hian Chew
    >
    >"Rohit Wason" <rohitw@ggn.hcltech.com> wrote:
    >>
    >>Hian,
    >>
    >>Try this:
    >>strString = rst.GetString columndelimeter:=vbTab, rowdelimeter:=vbCrLf
    >>
    >>This will store the whole recordset (text formatted) into a string.
    >>Then you can print this string using Word.Document OLE automation(thats

    >quite
    >>handy):
    >>
    >>Dim app As Word.Application
    >>Dim doc As Word.Document
    >>
    >>set app = GetObject("Word.Application")
    >>Set doc = app.Documents.Add
    >>With doc
    >> .Content = strString
    >> .Printout
    >>End With
    >>
    >>Hope it helps
    >>Cheers
    >>Rohit

    >



  8. #8
    Hian Chew Guest

    Re: print recordset


    I used recordset.save and open the file using text editor,
    it seems like it is not saved in ASCII format.
    Is there a problem here?

    Hian


    "Filipo Novo Mór" <fmor@terra.com.br> wrote:
    >
    >
    > Hi, Hian!
    >
    > The easiest way to do this is calling the wordpad (or other text editor
    >you have installed) and open the text with it (You can use the Shell function).
    >Otherwise, if you don't want to depend on external program, you can open
    >the text in VB and print it line to line:
    >
    >------------------------------------------
    >Dim Arq As Integer
    >Dim Line As String
    > Arq = FreeFile
    >open "c:\mytext.txt" for input as #Arq
    >While Not Eof(Arq)
    > Line Input #Arq, Line
    > Printer.Print Line
    >Wend
    > Close (Arq)
    > Printer.EndDoc
    >------------------------------------------
    >
    > I hope it helps!
    >
    > Filipo
    >
    >
    >
    >"Hian Chew" <hschew00@yahoo.com> wrote:
    >>
    >>If I use Save method of the recordset,
    >>How do I do the printing from file?
    >>
    >>Hian
    >>
    >>
    >>
    >>"Filipo Novo Mór" <fmor@terra.com.br> wrote:
    >>>
    >>>"Hian Chew" <hschew00@yahoo.com> wrote:
    >>>>
    >>>>I have to print an ADO recordset.
    >>>>What is the efficient way to send the recordset to the printer?
    >>>>Seems like doing record iteration printing is very slow
    >>>>for large recordset. Can someone point me to the right direction?
    >>>>
    >>>>Hian Chew
    >>>
    >>> Hian,
    >>>
    >>> You can save the recordset content in a file and then print the file.

    >>You
    >>>can do this using the Save method of the recordset object.
    >>>
    >>> Filipo
    >>>
    >>>

    >>

    >



  9. #9
    Filipo Novo Mór Guest

    Re: print recordset



    Hi, Hian!

    Nothing is wrong, here. I'd searched about and discover that this method
    save in a proprietary format. The only option you have, in this case, is
    save the recordset in XML format.

    Filipo


    "Hian Chew" <hschew00@yahoo.com> wrote:
    >
    >I used recordset.save and open the file using text editor,
    >it seems like it is not saved in ASCII format.
    >Is there a problem here?
    >
    >Hian
    >
    >
    >"Filipo Novo Mór" <fmor@terra.com.br> wrote:
    >>
    >>
    >> Hi, Hian!
    >>
    >> The easiest way to do this is calling the wordpad (or other text editor
    >>you have installed) and open the text with it (You can use the Shell function).
    >>Otherwise, if you don't want to depend on external program, you can open
    >>the text in VB and print it line to line:
    >>
    >>------------------------------------------
    >>Dim Arq As Integer
    >>Dim Line As String
    >> Arq = FreeFile
    >>open "c:\mytext.txt" for input as #Arq
    >>While Not Eof(Arq)
    >> Line Input #Arq, Line
    >> Printer.Print Line
    >>Wend
    >> Close (Arq)
    >> Printer.EndDoc
    >>------------------------------------------
    >>
    >> I hope it helps!
    >>
    >> Filipo
    >>
    >>
    >>
    >>"Hian Chew" <hschew00@yahoo.com> wrote:
    >>>
    >>>If I use Save method of the recordset,
    >>>How do I do the printing from file?
    >>>
    >>>Hian
    >>>
    >>>
    >>>
    >>>"Filipo Novo Mór" <fmor@terra.com.br> wrote:
    >>>>
    >>>>"Hian Chew" <hschew00@yahoo.com> wrote:
    >>>>>
    >>>>>I have to print an ADO recordset.
    >>>>>What is the efficient way to send the recordset to the printer?
    >>>>>Seems like doing record iteration printing is very slow
    >>>>>for large recordset. Can someone point me to the right direction?
    >>>>>
    >>>>>Hian Chew
    >>>>
    >>>> Hian,
    >>>>
    >>>> You can save the recordset content in a file and then print the file.
    >>>You
    >>>>can do this using the Save method of the recordset object.
    >>>>
    >>>> Filipo
    >>>>
    >>>>
    >>>

    >>

    >



  10. #10
    Hian Chew Guest

    Re: print recordset


    I have background activities (communication thought comm port)
    going on while printing. I will like to send the print job to
    the printer and exit the sub that do the codes that you have
    suggested. How do I know that the print job is done so that I
    can close/quit the word document from code?
    If I close quit it after the .printout statement, then
    a prompt is popped up saying the printing will be cancelled if
    quit.
    How to deal with this?

    Hian



    "Rohit Wason" <rohitw@ggn.hcltech.com> wrote:
    >
    >Hian,
    >
    >>Does this work ok on the computer where Word application is not installed?

    >
    >No this doesn't work without Word.
    >
    >>Do I have to set close or nothing on any of these object after use?

    >
    >Document.Close (False)
    >
    >
    >Cheers,
    >Rohit
    >
    >>
    >>Hian Chew
    >>
    >>"Rohit Wason" <rohitw@ggn.hcltech.com> wrote:
    >>>
    >>>Hian,
    >>>
    >>>Try this:
    >>>strString = rst.GetString columndelimeter:=vbTab, rowdelimeter:=vbCrLf
    >>>
    >>>This will store the whole recordset (text formatted) into a string.
    >>>Then you can print this string using Word.Document OLE automation(thats

    >>quite
    >>>handy):
    >>>
    >>>Dim app As Word.Application
    >>>Dim doc As Word.Document
    >>>
    >>>set app = GetObject("Word.Application")
    >>>Set doc = app.Documents.Add
    >>>With doc
    >>> .Content = strString
    >>> .Printout
    >>>End With
    >>>
    >>>Hope it helps
    >>>Cheers
    >>>Rohit

    >>

    >



  11. #11
    marc Guest

    Re: print recordset


    A quick and dirty way to print a recordset

    dim lngCurrentY as long, lngCurrentX as long, lngLoop as long

    dim strPrint as String

    cost Y_Start = 360, X_Start = 360, Y_Increment = 300

    'open recordset

    lngCurrentY = Y_Start

    with Printer
    do until recordset.eof
    lngCurrentX = X_Start

    For lngLoop = 0 to recordset.Fields.Count
    .CurrentX = lngCurrentX
    .CurrentY = lngCurrentY
    strPrint = recordset.Fields(lngLoop).Value
    Printer.Print strPrint
    lngCurrentX = lngCurrentX + .TextWidth(strPrint) + 200
    Next

    lngCurrentY = lngCurrentY + Y_Increment
    recordset.MoveNext
    Loop
    End With

    Marc

    "Hian Chew" <hschew00@yahoo.com> wrote:
    >
    >Does this work ok on the computer where Word application is not installed?
    >Do I have to set close or nothing on any of these object after use?
    >
    >Hian Chew
    >
    >"Rohit Wason" <rohitw@ggn.hcltech.com> wrote:
    >>
    >>Hian,
    >>
    >>Try this:
    >>strString = rst.GetString columndelimeter:=vbTab, rowdelimeter:=vbCrLf
    >>
    >>This will store the whole recordset (text formatted) into a string.
    >>Then you can print this string using Word.Document OLE automation(thats

    >quite
    >>handy):
    >>
    >>Dim app As Word.Application
    >>Dim doc As Word.Document
    >>
    >>set app = GetObject("Word.Application")
    >>Set doc = app.Documents.Add
    >>With doc
    >> .Content = strString
    >> .Printout
    >>End With
    >>
    >>Hope it helps
    >>Cheers
    >>Rohit

    >



  12. #12
    marc Guest

    Re: print recordset


    additions and corrections to A quick and dirty way to print a recordset

    dim lngCurrentY as long, lngCurrentX as long, lngLoop as long

    dim strPrint as String

    const Y_Start = 360, X_Start = 360, Y_Increment = 300

    'open recordset

    lngCurrentY = Y_Start

    with Printer
    do until recordset.eof
    lngCurrentX = X_Start

    if lngCurrentY + Y_Increment > 15840 then 'Length of an 11 inch piece
    of paper in twips (1440 twips per inch)
    .NewPage
    lngCurrentY = Y_Start
    End if

    For lngLoop = 0 to recordset.Fields.Count - 1
    .CurrentX = lngCurrentX
    .CurrentY = lngCurrentY
    strPrint = recordset.Fields(lngLoop).Value
    Printer.Print strPrint
    lngCurrentX = lngCurrentX + .TextWidth(strPrint) + 200
    Next

    lngCurrentY = lngCurrentY + Y_Increment
    recordset.MoveNext
    Loop

    .enddoc
    End With

    A more complicated check can be done for page width, involves looping to
    a certain field moveing to the first record and looping from that field to
    the next end point. This can be used regardless of the other software you
    have installed.

    Marc



    "marc" <whale@ultranet.com> wrote:
    >
    >A quick and dirty way to print a recordset
    >
    >dim lngCurrentY as long, lngCurrentX as long, lngLoop as long
    >
    >dim strPrint as String
    >
    >cost Y_Start = 360, X_Start = 360, Y_Increment = 300
    >
    >'open recordset
    >
    >lngCurrentY = Y_Start
    >
    >with Printer
    > do until recordset.eof
    > lngCurrentX = X_Start
    >
    > For lngLoop = 0 to recordset.Fields.Count
    > .CurrentX = lngCurrentX
    > .CurrentY = lngCurrentY
    > strPrint = recordset.Fields(lngLoop).Value
    > Printer.Print strPrint
    > lngCurrentX = lngCurrentX + .TextWidth(strPrint) + 200
    > Next
    >
    > lngCurrentY = lngCurrentY + Y_Increment
    > recordset.MoveNext
    > Loop
    >End With
    >
    >Marc
    >
    >"Hian Chew" <hschew00@yahoo.com> wrote:
    >>
    >>Does this work ok on the computer where Word application is not installed?
    >>Do I have to set close or nothing on any of these object after use?
    >>
    >>Hian Chew
    >>
    >>"Rohit Wason" <rohitw@ggn.hcltech.com> wrote:
    >>>
    >>>Hian,
    >>>
    >>>Try this:
    >>>strString = rst.GetString columndelimeter:=vbTab, rowdelimeter:=vbCrLf
    >>>
    >>>This will store the whole recordset (text formatted) into a string.
    >>>Then you can print this string using Word.Document OLE automation(thats

    >>quite
    >>>handy):
    >>>
    >>>Dim app As Word.Application
    >>>Dim doc As Word.Document
    >>>
    >>>set app = GetObject("Word.Application")
    >>>Set doc = app.Documents.Add
    >>>With doc
    >>> .Content = strString
    >>> .Printout
    >>>End With
    >>>
    >>>Hope it helps
    >>>Cheers
    >>>Rohit

    >>

    >



  13. #13
    Rohit Wason Guest

    Re: print recordset


    Hian

    >I have background activities (communication thought comm port)
    >going on while printing. I will like to send the print job to
    >the printer and exit the sub that do the codes that you have
    >suggested. How do I know that the print job is done so that I
    >can close/quit the word document from code?


    <Rohit>
    There is a property "Application.BackgroundPrintingStatus As Long" Just check
    on that, probably this hjas a value that suggests you that the PrintJob is
    going on. You may use this before quitting Word Application.
    </Rohit>


    >If I close quit it after the .printout statement, then
    >a prompt is popped up saying the printing will be cancelled if
    >quit.
    >How to deal with this?


    <Rohit>
    I dont see any Event (neighther of Application or of Document) that indicates
    the completion of a PrintJob. You might have to loop (?) and keep checking
    the value of BackgroundPrintingStatus (I also hate doing that). If you find
    a better way of doing tis in Word Application, tell me that too.
    </Rohit>



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center