Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing closed reports 1

Status
Not open for further replies.

CleoMan

Programmer
Jun 18, 2003
110
ZA
I have a loop that executes SQL, which I use to create a report from. The loop basically goes through a Debtors table and I want to create a single report for each debtor. But here are the 2 problems:

1) How do I print a report without opening it, because there might be a hundred Debtors or 10;either way the user does not want to see all these reports opening.

2) Because I use the same Answer table for the report over and over in the loop,
the first time I open the report everything is fine, but as soon as I try to open a
second, while the first one is still open, I get a error saying that the Answer table already exists

Any help or suggestions would be immensely appreciated
 
CleoMan,

1, There is no need to open a report to print it,
var
rep report
endvar

rep.print("reportName")

2 You can't run SQL and create an Answer table while that table is in use. You will need to close the report then run the SQL then open the report again. But then this wouldn't be a problem if you don't open the report to print, back to question one.

Hope this helps
Perrin
 
CleoMan,

While I can't disagree with what Perrin's said, I tend to handle this sort of thing differently. (Which makes sense, when you think about it.)

I actually like to open reports before printing them, for I've found this helps potential errors opening the reports (which print() does in the background).

However, to keep the user's from seeing the reports (when they don't want to), I open the reports minimized. This places a small icon on the Paradox desktop. (While it's possible some might find this disconcerting, I've never had any complaints about it.)
Also, I tend to close reports run in series before opening the next one. I do this by wrapping the basic login in a custom method and then calling that from my control code. For example:

Code:
method runRpt( strRptName String, strMaster String )
var
   rpt  Report
   roi  ReportOpenInfo
endVar

   roi.Name = strRptName
   if strMaster <> &quot;&quot; then
      roi.MasterTable = strMaster
   endIf
   roi.WinStyle = winStyleMinimize

   if GF_PREVIEW then
      rpt.wait()
   else
      rpt.print()
   endIf
   sleep()
      
   try
      rpt.close()
   onFail
      ; do nothing; it's already closed
   endTry
endMethod

Now, this works around your &quot;ANSWER already in use error&quot; because it automatically closes the report after it's finished. I generally use this code, or something like it, as follows:

Code:
   liCustID = pickCustomer()
   runQry( &quot;CUSTRPT1&quot;, liCustID )
   runRpt( &quot;CUSTRPT1&quot;, &quot;:priv:answer.db&quot; )
   runQry( &quot;CUSTRPT2&quot;, liCustID )
   runRpt( &quot;CUSTRPT2&quot;, &quot;:priv:answer.db&quot; )
   ; and so on...

(By the way, that error exists to protect your data. After all, if you're reviewing data, you probably don't want it blown away from underneath you.)

Also, I should say that this is more of a proof of concept than actual production code. I typically use a lot more error checking in my applications. However, it illustrates the basic idea. Specifically, use custom methods (and libraries) to reduce the amount of work (and code) you need to do repetitive tasks, such as printing reports, opening forms, and so on.

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top