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

Multi-copy reports - different caption in each copy

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I have a report (a credit note) of which I wish to print multiple copies.

I say REPORT FORM zzzz -COPIES 3 . . .

Each copy is the same except that each will have a caption somewhere which says "Accounts copy" or "Customer copy" or "Something else"

At one time I did not use the -COPIES clause, but invoked the reporter three times, setting a variable "zcopy" = 1,2,3, which I could test with an IIF(zcopy = 1, . .&c) statement.

Can I do the same thing by setting and incrementing a variable during the production of the report, and how do I do that.

Thanks AndrewM.
 
You can do the same thing during the production of the Report data.

Something like the following would work:
Code:
* --- Create Data Set For Copy #3 ---
SELECT *, PADR("Accounts Copy",16) AS Caption;
   FROM MyData;
   WHERE <whatever> ;
   INTO CURSOR RptData READWRITE

SELECT RptData
GO BOTT
nLastRec = RECNO()

* --- Create Data Set For Copy #2 ---
APPEND FROM DBF('RptData')
REPLACE ALL Caption WITH PADR("Customer Copy",16) ;
   FOR RECNO() > nLastRec
GO BOTT
nLastRec = RECNO()

* --- Create Data Set For Copy #1 ---
APPEND FROM DBF('RptData')
REPLACE ALL Caption WITH PADR("Something Else",16) ;
   FOR RECNO() > nLastRec

* --- Print Report Using 'Caption' Field As Group ---
* --- Within Report Form Have Group Change Launch New Page ---
SELECT RptData
REPORT FORM MyReport NOCONSOLE TO PRINT

Good Luck,
JRB-Bldr
 
Hi Andrew,

Does VFP actually have a COPIES clause in the REPORT command? I don't see it.

Jim
 
I too have never seen the COPIES option.

BUT even if it did exist, it would not do as described above.
It would work like the 'Number of Copies' in the Windows Application's PRINT utility and create 3 EXACT copies of the document, not 3 differing 'copies' of the document (each with a different caption).

Good Luck,
JRB-Bldr
 
The REPORT FORM command does not have COPIES clause (and never has, as far as I know). But VFP does have the _pcopies system variable, which can be used to control the number of copies.

However, in this case, I would think the simplest solution would be to run the report in a loop, setting a private variable to the required value on each iteration. Something like this:

Code:
PRIVATE pcHeading

FOR lnI = 1 TO 3
  
  pcHeading = ICASE( ;
    lnI = 1, "Accounts Copy", ;
    lnI = 2, "Office Copy", ;
    lnI = 3, "Customer Copy" )

  REPORT FORM CreditNote TO PRINTER NOCONSOLE

ENDFOR


You would then reference pcHeading from an expression in the report. The fact that it's private ensures that it will be in scope.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thanks Mike, jrbbldr, JimStarr.

You are right. There is no -COPIES clause in the REPORT FORM command. You have to include a line saying (e.g.) COPIES = 1 in the expr field of the first record (Objtype =1) in the .frx file and this achieves the result.

Mike. calling REPORT FORM in a loop is how I used to do it; but I am now using the COPIES option; my original reason was to save on the overhead each time I called REPORT FORM, I would like to know if I can set a variable within the report and increment it within the .frx processing, so that it gets different values (1,2,3) that I can test it within a field that I have defined on the report layout. I appreciate that your approach does this, but at present the "COPIES =" option is built into my program and I would like to work that way if possible.

Thanks. Andrew
 
I usually set up a function which decodes a variable into a string like this:
Code:
FUNCTION DECODEMATLCOPYNO
	PARAMETERS m.COPYNO
	PRIVATE m.COPYNO,m.STRING
	DO CASE
	CASE m.COPYNO = 1
		m.STRING = "Supplier Copy"
	CASE m.COPYNO = 2
		m.STRING = "Site Copy"
	CASE m.COPYNO = 3
		m.STRING = "File Copy"
	CASE m.COPYNO = 4
		m.STRING = "Accounts Copy"
	OTHERWISE
		m.STRING = ""
	ENDCASE
	RETURN(m.STRING)

Then I put that function as the control for a text filed on the report:
Code:
DECODEmatlCOPYNO(M.COPYNO)

And when I run the report I control the copies like this:

Code:
PRIVATE m.COPYNO
_PCOPIES = 4
m.COPYNO = 0
PRINTJOB
	m.COPYNO = m.COPYNO+1
	REPORT FORM RENTALORDER TO PRINTER NOCONSOLE
ENDPRINTJOB

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Thanks Griff. That certainly works, but I am back to effectively calling REPORT FORM three times (albeit within the PRINTJOB structure). The disadvantage is that there is an overhead of a few seconds between printing each document, whereas if I use the COPIES=3 clause within the .frx file the 3 pages come out continuously.

I had hoped that there might have been a way of setting a variable within the .frx file (I know that at least is possible) and then incrementing it each time the VFP report engine goes onto thge next copy (or perhaps when it prints the footer). I am not familiar with manipulating variables within an .frx, but I hoped that might be possible.

regards. Andrew M.
 
Andrew,

I'm not sure I understand about putting COPIES = 1 in the Expr field in the first record.

However, if you are saying that the report has access to a variable, named COPIES, which tells it which copy is currently printing, then the whole thing is quite simple. In the field that displays the required title, use this expression:

Code:
ICASE( ;
    COPIES = 1, "Accounts Copy", ;
    COPIES = 2, "Office Copy", ;
    COPIES = 3, "Customer Copy" )

But I don't see how COPIES would get incremented. For that matter, how do you actually tell the report to print three copies, other than in a loop?

Do you get the user to select three copies in the report's PROMPT dialogue? If so, you're not sending three separate reports to the printer; you're merely telling the printer driver to print the identical data three times. There's no opportunity to vary the data for each copy, so none of these methods would work.

Unless I've misunderstood what you are doing, you might have to stay with your loop.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Create a function:

FUNCTION printit

IF_pageno = 1
myvar = myvar + 1 && myvar is public
ENDIF

DO CASE
CASE myvar = 1
RETURN 'Accounts copy'
CASE myvar = 2
RETURN 'Customer copy'
OTHERWISE
RETURN 'Something else'
ENDCASE


In calling program:

PUBLIC myvar
myvar = 0
REPORT FORM zzzz TO PRINT


In report, to print the heading use;

printit()



Jim
 
I'm guessing that the COPIES=3 in the frx file tells the printer driver to print three copies of whatever page you're sending to it.
Since the report image has already been rendered by VFP then sent to the printer including the COPIES parameter, I don't believe you would be able to utilize the COPIES parameter as a parameter in the report as in Mike's ICASE statement. I think you're stuck with running the report 3 times using your own variable or header-type field.



-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Andrew,

OK, I see now what you mean by putting COPIES in the Expr field. It has the same effect as if you printed the report from the report designer, and selected more than one copy in the printer dialogue.

If that's right, none of the methods discussed here will work. VFP will simply tell the printer driver to print whatever data it gets three times. Only one lot of data will reach the printer, so there will be no opportunity to change any values.

The only solution is to go back to using a loop. In that case, I think you'll find that the code I posted in my first message will do what you want.

Jim and Griff:

Even if I'm wrong about this (and I might well be), I don't see the point in writing a separate function. Using an ICASE() is neater and simpler.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Hi Mike

I use a function rather than the ICase because sometimes I need the result to come from a table (rather than fixed labels dependant on the value of m.COPYNO) so I can modify the code to do whatever I want - without changing the underlying report!

Of course using an ICase may be faster - which could make a difference if you were using xfrx to create pdf files!

Regards

Griff
Keep [Smile]ing

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

In my solution the report calls a function which increments a variable each time _pageno = 1. The function thus returns a different value to print with each pass, and the REPORT command is executed only once.

Jim
 
Very clever Jim!

Regards

Griff
Keep [Smile]ing

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

I see what you mean about incrementing a variable each time you hit page one. And I agree that would invalidate the use of ICASE().

But I still think the program would only send one set of report data - the actual text that the printer driver receives - so _pageno will always be 1 on the first page only.

What I'm trying to say is that, if you tell the printer driver to print three copies, the copies will be identical - by definition. By the time the report is sent to the printer, VFP has finished with it, and so has no opportunity to change any text.

Griff,

I also take your point about accesing a table in the function. In the example I have been using, that's not an issue, but I can see that it might be at other times.

Andrew,

Have you tried any of these suggestions yet? It would be interesting to know what works and what doesn't.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike

I hadn't thought of that, if the 'copies' is implemented at the printer driver, then you are right - it prints 3 duplicates of the same thing, regardless of the page number.

I think printJob/endprintjob is probably the most elegant way to go.

Martin

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
That's pretty much what I was talking about when I said above:

It would work like the 'Number of Copies' in the Windows Application's PRINT utility and create 3 EXACT copies of the document, not 3 differing 'copies' of the document (each with a different caption).

Good Luck,
JRB-Bldr
 
Mike and everyone

I have tried these various suggestions and have reverted to calling REPORT FORM in a loop. So I set and increment a variable (zCopy) outside a loop and display my caption by using a function which supplies that variable (zCopy) as a parameter.

This is pretty much as I had done it before. I had hoped that by setting a variable and incrementing it in (say) the end of the page header, that would do the trick, using the COPIES=3 clause. But as has been pointed out, using this clause just tells the printer driver to print the identical pages : the page generation only gets done once so my attempt to increment a variable within the form was doomed to failure.

Thank you all for your help and patience in this matter. Even an unsuccessful search for a solution has added to my knowledge!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top