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!

Showing individual pages when previewed but only prints one page in print mode 2

Status
Not open for further replies.

Steve-vfp9user

Programmer
Feb 5, 2013
337
GB
Hello

I am using VFP9 SP2.

There is a single field within my table called YESORNO

I am using the following code in an attempt to only print single page reports when the condition is satisfied which works when I preview the report but only prints the first record if I change the command to print:

Code:
SCAN
   mthisrec=0
   mthisrec=RECNO()

   IF YESORNO="N"
      REPORT FORM singlepagereport NOCONSOLE PREVIEW FOR RECNO()=mthisrec  &&  THIS WORKS AND SHOW A PAGE PER RECORD

*      REPORT FORM singlepagereport NOCONSOLE TO PRINTER FOR RECNO()=mthisrec  &&  THIS DOESN'T WORK AND ONLY PRINTS THE RECORD
   ENDIF

ENDSCAN

There are three records satisfying the condition in the table.

I've checked out the help file and used WHILE, NEXT etc but everything works in PREVIEW mode but not in print.

What am I doing wrong guys?

Thank you

Steve
 
You ask for data from one record, and that's what you get. Why are you so surprised?
 
The reason is after the REPORT FORM you're at EOF(), the FOR condition only prints the record with the recno you put into mthisrec, but the scoping mechanism means a loop in itself.
Since no further records fullfill RECNO()=mthisrec you end up at EOF.

If you want to use the YESORNO column as a filter then either just use one REPORT FORM with the FOR condition FOR YESORNO="N" or don't use a FOR condition and simply report the current record only with the scope of NEXT 1.

OK, that said I notice the difference between preview and no preview. But do you really get several previews after each other?

Notice one more thing: If your report has its private data environment you can't control it from outside with scopes at all. The report driving cursor then will be what the datasession has as initially selected alias. Anyway, if you want one preview or print with all records/pages fulfilling the condition a scan loop is the wrong thing.

Bye, Olaf.

 
You seem to have commented out the second report line, so it probably wouldn't work anyway.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Are you aware that you can combine PREVIEW and TO PRINTER in the same command? You don't need two REPORT FORM commands.

But still, it makes little sense to do a preview within a Scan loop.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I think there is a bug in the scan/endscan when used with report ... to printer.

Code:
SCAN
   mthisrec=0
   mthisrec=RECNO()

   IF YESORNO="N"
      REPORT FORM singlepagereport NOCONSOLE PREVIEW FOR RECNO()=mthisrec  &&  THIS WORKS AND SHOW A PAGE PER RECORD

*      REPORT FORM singlepagereport NOCONSOLE TO PRINTER FOR RECNO()=mthisrec  &&  THIS DOESN'T WORK AND ONLY PRINTS THE RECORD
   ENDIF

ENDSCAN


You could use the following to achieve with slight changes to your original code.

Code:
FOR mthisrec = 1 to RECCOUNT()

   IF YESORNO="N"
      REPORT FORM singlepagereport NOCONSOLE PREVIEW FOR RECNO()=mthisrec  &&  THIS WORKS AND SHOW A PAGE PER RECORD

*      REPORT FORM singlepagereport NOCONSOLE TO PRINTER FOR RECNO()=mthisrec  &&  THIS DOESN'T WORK AND ONLY PRINTS THE RECORD
   ENDIF

ENDFOR
 
My answer was too quick. Follow what others have said regarding EOF() condition.

I just tested and found: when used with "report form ... preview" the file pointer remains at the current position, but "report form ... to printer" the file pointer is at the eof().

PS: So using FOR/ENDFOR will fix the issue.
 
So using FOR/ENDFOR will fix the issue.

Are you sure about that, Nasib?

As far as I can see, all that your code will do is to show the preview - for the entire table - x times, where x is the number of records in the table (including deleted and out-filtered records).

At the very least, you want to add a SKIP to the loop, but even that won't achieve anything useful. All that you will have achieved is to replace a SCAN loop with a FOR loop.

Mike






__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
>when used with "report form ... preview" the file pointer remains at the current position, but "report form ... to printer" the file pointer is at the eof().
both of that is news to me.

Anyway you wouldn't do any loop, you would use a FOR condition in one REPORT FORM command, either with or without preview.

You don't want print jobs for every single page. Other print jobs then could go in between and collecting the pages of your report might mix in someone elses totally unrelated report print. Less important for a smaller company or a unshared local printer, but face it, just for maintainance and readability, I'd always choose the fewer code.

Code:
REPORT FORM singlepagereport NOCONSOLE PREVIEW FOR YESORNO="N"

That's all to it.

At least after you made the detail band of the report so high, that only one record fits the page. Also use group header/footer instead of report headder/footer, if it matter to have these sections besides the detail area for each record and create report grouping by recno(), making each record its own group.

Bye, Olaf.
 
One reason to have N report print jobs would be wanting N pdf files as output. Let me assume that, then the easiest solution to not let the report alter the record pointer of an outer loop would be:

Code:
SELECT yourtable
SCAN FOR YESORNO="N"
   REPORT FORM singlepagereport NOCONSOLE TO PRINTER NEXT 1
ENDSCAN
Untested. If that won't work, then first select all rercords where YESORNO="N" into a cursor you loop and do the REPORT FORM calls with the main table selected and FOR a certain record no or id you get from the loop cursor, so you have two independent record pointers and the report doesn't influence the loop cursor.

Bye, Olaf.
 
You know, before we keep on with this, maybe we should wait for the original questioner to reply to our existing suggestions. We still don't know what he is trying to achieve. Does he really want to show multiple previews in a loop? Or is it simply a matter of displaying a single report for records that meet the condition?

Until we understand the requirements, there seems little point in guessing the answers.

What do you say, Steve?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi

Firstly the reason for the two report command within SCAN ENDSCAN were there whilst I was testing the code and to show that I was getting the desired result using preview. Sorry if this caused any confusion.

Mike's last post:

What I was trying to achieve was to print a single page report for each record matching the condition within the selected table so if there were only 3 records matching FOR YESORNO="N" and 2 FOR YESORNO="Y" I only required the FOR YESORNO="N"

Olaf's code below resolved the issue (and I'm not sure why I didn't find that)

Code:
SCAN FOR YESORNO="N"
   REPORT FORM singlepagereport NOCONSOLE TO PRINTER NEXT 1
ENDSCAN

I appreciate your posts, time and effort and for others, please keep in mind that we are not all experts until we reach your level!

Thank you

Steve
 
Steve,

Good that you've got a solution. And of course we all understand that not everyone here is an expert. That's what the forum is all about: so that the more knowledgeable members can help those with less experience. I hope I didn't give you a different impression.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Well, if there is no reaport header/footer only printing once but mainly the detail band, you don't even need the scan loop, REPORT FORM itself knows the FOR clause.

Code:
REPORT FORM singlepagereport NOCONSOLE TO PRINTER FOR YESORNO="N"

That's all there is to it, despite it prints header/footer only once and it doesn't work for reports with private datasession.

Anyway, you got it now.

Bye, Olaf.
 
Hey Mike, of course not. I'm a great learner and guys like you and Olaf give guys like me the additional knowledge required. I was thinking more so nearer the top of this thread.

Happy New Year for 2016 all

Thank you

Steve
 
Are you sure about that, Nasib?

Yes Mike, I am sure. There is no need of skip because "for" of the report will do it.

Deleted record ? You are right. I am trying to answer his(vf9user) base question that "preview" works but "to printer" does not. And he is right. If un-comment the second "report form ... to printer' line, the behavior is exactly what vf9user described.



 
>both of that is news to me.

Olaf, it is new to me as well until I insert some debug code as follows.

Code:
SCAN
   mthisrec=0
   mthisrec=RECNO()

   IF YESORNO="N"
      REPORT FORM singlepagereport NOCONSOLE PREVIEW FOR RECNO()=mthisrec  
      ? recno()  && Debug code
      REPORT FORM singlepagereport NOCONSOLE TO PRINTER FOR RECNO()=mthisrec 
      ? recno()  && Debug code
   ENDIF

ENDSCAN
 
NasibKalsi,

I would consider this a bug. So preview with such a FOR clause does not advance the record pointer to the end, while the command without PREVIEW does. What really matters is the PREVIEW clause, TO PRINTER PREVIEW also causes single previews and does not advance the record pointer to EOF.

There is a fix for that, though, use REPORTBEHAVIOUR 90 and the record pointer moves - as it should - to EOF.

That means, Steve, without the bug in the PREVIEW behaviour your test would have told you your idea of things was wrong. A FOR clause always means a scan loop on its own (at least it should) and if you nest two scan loops on the same table the inner loop going to EOF will also end the outer loop, they both use the same "counter variable", the record pionter of the same workarea, that's like doing two nested FOR loops with the same counter variable.

Bye, Olaf.

PS: Just a sidenote, I already gave the answer you needed earlier without putting it in code:
If you want to use the YESORNO column as a filter then either (1) just use one REPORT FORM with the FOR condition FOR YESORNO="N" or (2) don't use a FOR condition and simply report the current record only with the scope of NEXT 1.
 

*** H A P P Y N E W Y E A R 2 0 1 6 to ALL Enjoy


My understanding was:
Report form ...,
a) Go TOP
b) Generate report as per 'FOR' condition if any
c) Go EOF
d) Other conditions such as 'FOR' is to limit the dataset scope, but it is not a scan.
e) 'next 1' as in Olaf' example. I did not know this, I think it cancels the 'skip' and record pointer does not move.

 
Hi Nasib
a) no need for that, FOR does that, simply try GO 2, REPORT FORM FOR Recno()=1, if you want to print record 2, NEXT 1 is needed, if you want to print from record 2 onwards REST is needed. Default scope of a REPORT is ALL records, so GO TOP is automatic when specifying no scope or FOR scopes.
b) Well, all scopes apply to the REPORT command as to any command accepting clauses, it only makes sense in a report without private datasession, though.
c) Well, the report does so while scanning its report driving cursor/table/view and you know that, you SEE it, the report prints all records. Also woth a FOR condition the recno doesn't stop at the last printed record. I haven't tested, but even with SET FILTER or SET KEY you should end at EOF of the report driving cursor with no scope (=default ALL), FOR or REST.
d) No, FOR condition is equal to a SCAN FOR loop (or should be).
e) Well, look up the definition of scopes, especially NEXT N scope.


By the way, as I viewed this, you might try REPORT FORM ... RECORD mthisrec, too.

Also notice, this is about record scopes in workareas, not about variable scopes, the common denominator should be clear from the natural language meaning of scopes.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top