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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing a print job

Status
Not open for further replies.

sdocker

IS-IT--Management
Aug 12, 2010
218
GB
I have an application that prints numerous forms based on user input. For example, if the forms are named 'A' to 'J', the print job can include any or all of the forms. There was a summary form that always printed at the end, so I simply used NOPAGEEJECT in all the forms except the summary.

Unfortunately, the summary page is no longer used, so I am faced with the task of determining which form will be printed last and and not use a NOPAGEEJECT, so the print kob will close..

My question is.... Is there VFP command to close a print job?

Incidentally, this is only an issue when printing to a PDF .

Thanks,
Sam
 
There isn't really something called a "print job" in Visual Foxpro.

You launch one or more printouts via the REPORT FORM <whatever>

In general, what code are you using to run your "print job"

Maybe something like (??):
Code:
FOR i = 1 to 10
   SELECT *;
     FROM MyData;
     WHERE <whatever>;
     INTO CURSOR ReportData

   SELECT ReportData
   REPORT FORM <whatever> TO PRINT
   CLOSE DATABASES ALL
ENDFOR

Otherwise, how is your code moving through the individual forms?

And, with that in mind, what do you need to accomplish after you have "determin[ed] which form will be printed last"?

Good Luck,
JRB-Bldr


 
The reports are pages of a government application. Each report is on a different form.

Code:
if m.FormA
   REPORT FORM m.FormA NEXT 1 TO PRINTER NOCONSOLE NODIALOG NOWAIT
endif

if m.FormB
   REPORT FORM m.FormB NEXT 1 TO PRINTER NOCONSOLE NODIALOG NOWAIT
endif
.
.
.
REPORT FORM m.Summary NEXT 1 TO PRINTER [b]NOPAGEEJECT[/b] NOCONSOLE NODIALOG NOWAIT

As long as I know which page is last, I know where to not use the keyword NOPAGEEJECT.

Sam
 
Well, your code does use the NOPAGEEJECT inversely from where it should be used.
You want no page eject in all BUT the last report.

All FormA,B,C... reports should have the NOPAGEEJECT and the summary should NOT have it.

help said:
To specify that Visual FoxPro does not force a sheet eject at the end of a report and leaves the print job open, include the NOPAGEEJECT keyword. The next report printed is added to the open print job.

You must make sure that the last report run does not have a NOPAGEEJECT clause so the print job can be closed.

NOPAGEEJECT is valid only during program execution. It is disregarded when issued in the Command window. Changing between page orientations, such as landscape to portrait, between reports is not supported.

You can chain multiple reports using NOPAGEEJECT and have page numbers continue from one report to the next. This is a useful technique for tasks such as faxing reports.

The one downside with this is, it'll not only keep the print job open which VFP maintains in the background for you, it also means no page eject, unless you only print full pages by having a page footer anyway. So finally you can use NOPAGEEJECT as way of doing KEEPPRINTJOBOPEN only, if your FormA,B,C,... reports all print full pages only. There is no option for just keeping the print job open and still doing a final page eject, so your Form reports have to handle that full page printing.

Bye, Olaf.

 
Because there is no separation of the two aspects of keeping a print job open but anyway eject and continue in the next page, you may be able to somehow enforce full page prints in reports with a footer or summary band (summay band, not meaning your summary report), it might also be easier to enforce any chained report to start on a new page by starting with a title band or page header.

I just remember questions about why reports don't continue in the page the previous report ended and so if you encounter that, you rather have found the holy grail others are searching for.

Anyway, your description hints on knowing to not use the keyword in the last report, but then you do exactly that.

Bye, Olaf.
 
Olaf,

Apologies for the confusion.
Code:
if m.FormA
   REPORT FORM m.FormA NEXT 1 TO PRINTER NOCONSOLE NODIALOG NOWAIT
endif

if m.FormB
   REPORT FORM m.FormB NEXT 1 TO PRINTER NOCONSOLE NODIALOG NOWAIT
endif
.
.
.
REPORT FORM m.Summary NEXT 1 TO PRINTER NOPAGEEJECT NOCONSOLE NODIALOG NOWAIT
 
sdocker,

that is, waht you already posted, and is wrong. Seems you have a problem with the double negation nature of theis option.

I also don't understand, why you have m. before the rpoert names. If these are variables holding the FRX names you should use REPORT FORM (m.Reportnamevariable), but that's leading off topic.

You have to put NOPAGEEJECT everywhere, you don't add it in the last REPORT FORM call.

Bye, Olaf.

 
Continued...

The code is correct. I displayed in this forum incorrectly.

Do i understand correctly, that you can you put a footer into each report to eject the page and not close the print job?

These reports do not have footers in them, but I will investigate this further.

Sam
 
Sam,

Why not create the REPORT FORM commands dynamically, and use macro substition to execute them?.

So, something like this:

Code:
lcCmd = "REPORT FORM " + <name of next report> + " NEXT 1 TO PRINTER NOCONSOLE NODIALOG NOWAIT"
IF <this is not the last form>
  lcCmd = lcCmd + " NOPAGEEJECT"
ENDIF
&lcCmd

Obviously, you will need a way to test "this is not the last form", but presumably the logic of your application provides a way for you to do that.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The print job closing has nothing to do with the nature of the report. Only the NOPAGEEJECT option keeps a print job open. There unfortunately is no KEEPJOBOPEN option only, we only can keep a print job open by using that option, which also does not eject the page.

You confuse cause and effect, if you think that a page eject closes a print job, or the suppression of a page eject keeps a job open. Page ejects are normal operation of a multi page report anyway, they are not coupled with jobs, just this VFP option does that. MS has given us one separate option called NOEJECT, which does not keep a job open, but is deprecated, so it does nothing at all and is unusable.

MS named the NOPAGEEJECT option this way, because they only thought of the case, where you want to continue printing with a new detail band of a secondary report at the line the previous report ended. If you print new reports on new pages, you don't even need this option in any of the REPORT FORM calls and could print each form and the summary in a separate print job. The OS doesn't need a single job to print all this, the only downside is, if printing to a central printer with many print jobs printing there and each job has its own output tray, you would need to collect all the pages you want from many trays and there might be totally different print outputs from other users, even from other applications.

So either you use the NOPAGEEJECT in all but the summary report and then handle the eventual problem of your Forms A,B,C not starting on their own new page, or you don't use the NOPAGEEJECT option at all and print all forms and summary in seperate pages in separate jobs.

Bye, Olaf.
 
Do you even have the problem eg FormA and FormC should be printed and FormC is not starting on its own new page after FormA?

Your code is wrong in another aspect regarding the memoery varriables. You have IF statements checking whether each report should run or not, mFomrA, mFormB, these should be booleans. You can't use the same boolean (logical .T. or .F.) variable as the report file name.

Are you getting any errors?

Please Sam, copy&paste your real code (or part of it) and tell uis about error messsages, and also don't suppress them in some error handler while developing and debugging code. You would gain so much more insight on what happens on your own.

Bye, Olaf.
 
Code:
if [b]m.FormA[/b]
   REPORT FORM [b]m.FormA[/b]
This can't work. A variable can't be a boolean (.T. or .F.) and a string (the report file name) at the same time.

Please post your real code and we can talk about your real problem.

Bye, Olaf.
 
Maybe you should just do one thing, Sam, take one hour off of programming. Ideally not even work on something else in the meantime. Then go back to the problem.

Bye, Olaf.
 
Sorry Olaf,

I made a mess of displaying the code.

This is actual..

Code:
If <FormA will be printed>
   lcreportForm = 'FormA'
   lcNoPageEject = 'NOPAGEEJECT'  &&  or '' if last page
   REPORT FORM &lcReportForm NEXT 1 TO PRINTER &lcNoPageEject NOCONSOLE NODIALOG NOWAIT
endif

Sam
 
How about creating a supplementary report, that print only an empty string, in other words nothing, and to run this report without NOPAGEEJECT, after the entire set of IF's?


Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

 
Sounds like it would work. But, it is a distributed app and i'm sure i'll hear about the extra empty page

Sam
 
I am faced with the task of determining which form will be printed last

Is your REAL problem knowing how/when to use NOPAGEEJECT or not?
You originally indicated that your problem was determining which form will be printed LAST.

If needing to know which is LAST, you could always run through a process identifying the needed forms BEFORE printing and thereby 'know' which is last BEFORE starting to do the actual printing.

One suggestion for this might be to put the needed forms into a Cursor.
For example:
Code:
CREATE RptForms (FormName C(20))
* --- Now do whatever to identify the needed forms ---
IF <FormA will be printed>
   lcreportForm = 'FormA'
   SELECT RptForms
   APPEND BLANK
   REPL FormName WITH lcreportForm
ENDIF
* --- <and so on> ---

* --- Now Print Forms ---
SELECT RptForms
nLastForm = RECCOUNT()
SCAN
   lcreportForm = RptForms.FormName

   * --- <Do whatever to get needed data> ---
   SELECT ReportData
   REPORT FORM (lcreportForm) TO PRINT

   SELECT RptForms
   IF RECNO() = nLastForm
      * --- Last Form Was Printed ---
      < Do Whatever >
   ENDIF

   SELECT RptForms
ENDSCAN

Good Luck,
JRB-Bldr
 
I don't see how that would not work, unless you set lcNoPageEject wrong. Perhaps DEBUGOUT lcReportForm+":"+lcNoPageEject before each REPORT FORM and see what you really do.
Your first pseudo codes suggested you always print a summary report last, then that is the only one to print without NOPAGEEJECT and you have no problem finding out which prints last.

Aside of that, don't use macro substitution in names, file names could contain spaces:

Code:
If <FormA will be printed>
   lcreportForm = 'FormA'
   lcNoPageEject = 'NOPAGEEJECT'  &&  or '' if last page
   REPORT FORM [b][highlight #FCE94F]([/highlight][/b]lcReportForm[b][highlight #FCE94F])[/highlight][/b] NEXT 1 TO PRINTER &lcNoPageEject NOCONSOLE NODIALOG NOWAIT
endif

Also if that matters could only be really said, if you show real code instead of pseudo code.

Bye, Olaf.


 
Rereading sometimes helps.

>the summary page is no longer used

You could have stressed that point by removing it from your code...

Anyway, then you have to split up the determination of what reports are printed and determining the last one of them, maybe with the code JRB-Bldr suggests.
If you already have an array of checkboxes to choose forms/pages, then you also know your print order or if statement order and have a secondary bool for each report, whether it is the last one in that processing order, eg the highest checkbox number or whatever.

You have to know this in advance, of course, you can't determine on the fly, whether a later IF statement will also print, so you have to split up determination of last report and printing of them.

Maybe go about it this way:

Code:
lcCommands = ""

If <FormA will be printed>
   lcreportForm = 'FormA'
   lcNoPageEject = 'NOPAGEEJECT'  &&  or '' if last page
   lcCommands = lcCommands + 'REPORT FORM ("'+lcReportForm+'") NEXT 1 TO PRINTER NOPAGEEJECT NOCONSOLE NODIALOG NOWAIT'+CHR(13)+CHR(10)
Endif 
*... many more IFs

*remove only last NOPAGEEJECT
STRTRAN(lcCommands,"NOPAGEEJECT","",OCCURS("NOPAGEEJECT",lcCommands),1)

* now execute:
EXECSCRIPT(lcCommands)

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top