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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

Data Report print not in order

Iam trying to print a data reports in a command click event.
but the print out is not in  the order iam i have coded it is printing randomly.why is it so how to correct it
0
sktripuraneni
Asked:
sktripuraneni
  • 6
  • 4
  • 4
  • +1
1 Solution
 
Anthony PerkinsCommented:
The data will print in the same order (or lack) of the recordset.

Solution:  Add an Order By clause to your SQL statement.
0
 
Ryan ChongCommented:
You need to put "Order By" in your SQL command line first:

Example:

DE.rsCommand1.Open "Select * from Adv Order By Adv"

regards.
0
 
sktripuraneniAuthor Commented:
no my exact question is there are 5 reports (different ones) in the command click event and they are not printing in the same order that is reprot 1 ,report2, report3.it is printing randomly 1 then 2 then 4 then 5 then3 some times and in other order some other times why so
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.

 
Ryan ChongCommented:
So, you mean you print 5 reports in a click event ?

Try to add some time buffer so each of them are printed accordingly.

You can add DoEvent function or do a For..Loop between the report's Print method.

regards.
0
 
sktripuraneniAuthor Commented:
i have tried using all the ways this how is the code

For printCheck = 1 To 4
    sqlquery$ = "select routenum, townname, projectnum, location from activity where distid=" & printCheck & " and projectnum <> 'N/A' order by routenum"
    Set sumDist1 = cn.Execute(sqlquery)
    Set dtrSumDist1.DataSource = sumDist1
    dtrSumDist1.PrintReport
    sqlquery = "select townname, projectnum, department, estcomp,detrep as detailedreport,location,routenum from activity where distid=" & printCheck & " order by townname;"
    Set Dist1 = cn.Execute(sqlquery)
    Set dtrDistrict1.DataSource = Dist1
    dtrDistrict1.PrintReport
Next printCheck

i also used a while loop, i tried also not using any loop
0
 
Arthur_WoodCommented:
You may be seeing an effect of the Buffering of the actual print files by the Printer Driver.

Many Printers will attempt to actually print the smallest PENDING file FIRST, even if that specific file was not actually SENT to the PRINTER first.  It has to do with the files PRIORITY in the PRINT QUEUE, over which your Program has very little control.

If that is what is happening, then the suggestion to add a time delay between the Print instructions in the Command Button Click Eevent handler would probably need to make those delays long enough to allow each File to be printed, BEFORE the next file is then sent to the Printer.

0
 
Ryan ChongCommented:
Hi,

How about something like this (Maybe a stupid one):

Add a Sleep API + DoEvents

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


For printCheck = 1 To 4
   sqlquery$ = "select routenum, townname, projectnum, location from activity where distid=" & printCheck
& " and projectnum <> 'N/A' order by routenum"
   Set sumDist1 = cn.Execute(sqlquery)
   Set dtrSumDist1.DataSource = sumDist1
   dtrSumDist1.PrintReport
   DoEvents:Sleep 5000 '% second rest
   DoEvents
   sqlquery = "select townname, projectnum, department, estcomp,detrep as detailedreport,location,routenum
from activity where distid=" & printCheck & " order by townname;"
   Set Dist1 = cn.Execute(sqlquery)
   Set dtrDistrict1.DataSource = Dist1
   dtrDistrict1.PrintReport
   DoEvents:Sleep 5000 '% second rest
   DoEvents  
Next printCheck

'Regards.
0
 
sktripuraneniAuthor Commented:
yes what arthur wood said is likely bcos the largest report is generally coming after a lot of shorter ones, so how to give a time delay in order to avoid this
0
 
Arthur_WoodCommented:
Doing what you may need to do IS NOT going to be easy, as there may be OTHER print jobs, sent to the printer, in between each of YOUR jobs, so that you have NO way of knowing, for sure, when any one of your Print jobs has ACTUALLY completed.

Just a thought- WHY is it IMPORTANT what order the reports are actually printed in?  Can't you (or the user) sort the reports (as separate set of pages) into whatever they want them, manually?
0
 
sktripuraneniAuthor Commented:
no it cannot be arranged manually bcos the system is on a network and the printer is many buildings away from me,i give a print job and they do not even know what that is they just punch them and are sent to other departments.so it is very important that the order is very important
0
 
sktripuraneniAuthor Commented:
so u mean to say that there is no way that we can control the data to printer.if any dta that is external to thses reports come out they can be removed but all the reports that come under the same project must be in order,so how can it be done
0
 
Arthur_WoodCommented:
What I am saying is that when you send a file to the printer, and then send ANOTHER file to the printer, between the time that you sent the FIRST file, and the SECOND file, some other user, MAY have sent thier own file.  And the PRINTER DRIVER will determine which file is PRINTED, in it's entirety, in what order.  You will not have pages from different print jobs mixed together, but the complete print jobs may be actually printed in an order over which you have very little control, from your program.  THe attempt is being made to make the actual printing as "efficient" as possible - and in your case, that is causing you a mjor headache.  Most of the time, this is not a serious problem, but it would appear that yours is one of a small percentage of circumstances where it IS a problem.  I do not think that there is anything that you can do about it, but I could be wrong.  This is a set of circumstances whcih I have NO direct experience with.
0
 
sktripuraneniAuthor Commented:
any way thank you very much for ur comments,i was actually a lot confused feeling that there is some error in my code but iam happy enough and i will try to solve it if i can.i accept ur comments as answers.also ryacns was also very helpful to me,thank you very much both of u.
0
 
Ryan ChongCommented:
Hi,

You're welcome.
0
 
Arthur_WoodCommented:
You're welcome.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 6
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now