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

a "simple" way to detect printing from print preview

Status
Not open for further replies.

markftwain

Technical User
Jul 12, 2006
108
Hi All,

Having read everything I can find (including Mike's FAQ), I can't seem to get a "this report has been printed" flag.

As simple as possible, how do you catch the user printing the report by print preview toolbar and report menu while it was being previewed?

I'm using VFP 9 sp2, Reportbehaviour 90.

Thanks
 
How about making use of SYS(2040)?

Help on the topic suggests an expression for a page of pagetotal display, which should only display the "of _pagetotal" part, when the is actually printed:

Code:
IIF( SYS(2040) = "1", "", " of " + TRANS(_PAGETOTAL))

SYS(2040) returns "2", when the report really is printed, so in that run you can set some variable, eg glPrinted=(SYS(2040) = "2") in the report footer. Previous to the report run set glPrinted=.F. and afterwards you can see, if the report was going into mode 2.

What you can't detect as far as I know is, if the report really is output. There are many things, which can still occur at the printer of course, eg paper jam.

Bye, Olaf.
 
Hi Olaf,

I tried placing glPrinted=(sys(2040)="2") in the "on entry" property of the report footer.

It appears that this is called only on the initial presentation of the report. That is, when the report is first viewed, it is called. But if the report is already being previewed, printing (the already in view report) by the printer tool bar or menu does not call the "on entry" property again. Hence, glPrinted is always .f.

Ideas?
 
It works within the band. eg have a control set to sys(2040) and it will display 1 in preview, 2 in the output.

Add a control and set it to print when .f. (never print), set it's expression to execscript("glPrinted=(sys(2040)='2')"), then glPrinted is set .T. when printing.

Bye, Olaf.
 
I added a control to every band (headers, footers, details, summary). sys(2040) always output "1" regardless of printing or viewing. I believe it is only acted upon first rendering of the report. (Controls do not seem to be reevaluated when printing from the view).

????
 
Sorry,

can't reproduce that, it works for me.
SET REPORTBEHAVIOR 90 perhaps?

Bye, Olaf.
 
I actually get 1 and 2 in preview and output with enginebahvior 80, too. You also said you're at VFP9 SP2, Enginebahvior 90, so this must work. I don't see a setting where sys(2040) behavior could be influenced. I also don't see how a report would not evaluate something twice, you render output for the screen in ~96dpi and with much higher resolutions for the real print output, vfp goes through each report twice for that reason alone.

Please start a very simple new report from scratch, put a table in the report DE, add a control to the PageFooter or Summary band and set it's expression to sys(2040), then preview (1) and print (2). Works for me and I checked it at home and in the office.

Bye, Olaf.
 
Mark,

Can I go back to your original question.

You said you tried the technique described in an FAQ, but couldn't get it to work. Are you referring to the idea of referencing WEXIST("Printing...") in a function, and calling this function from an expression in the report?

If so, I can only say that this has worked for me. It is a long time since I used, so I might be mistaken on some of the details, but I don't know of any problem with it.

What happened when you tried it? In what way didn't it work?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Hi Mike,

I am unsure how to call a procedure from within the reports "on entry" field when that procedure is one of many other procedures inside a .prg file.

I am probably very wrong on this, but here is my experience:

When simply putting a messagebox() in the "on entry", or in any control on the form, it would seem that with reportbeviour 90 the messagebox() (and all rendering) for the report is only called once for the preview. Printing the report after the preview has been generated does not seem to call any expression again. So sys(2040) and other run-time checks fail to indicate user selected to print.

I'm sure this problem comes often, what is the best way to do this?

Thanks
 
Mark,

So, you are saying that the function is only called for the preview, and not for the subsequent print? It's as if VFP is saying: OK, I've already got the value of this function, I don't need to get it again.

If so, I find that surprising. After all, if the function was called from the detail band, you would expect it to be called for every record. It must to that regardless of whether it was called before.

But I'll take your word for it. You are closer to the problem than I am.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Can you use Mike Gagnon's FAQ and simple modify the code to set a flag.

faq184-2919

Jim
 
Mark,

I just ran a quick test: I put an expression in the detail band. The expression calls a function that detects WEXIST("Printing...") and sets a variable (as in the FAQ).

When I ran it in the preview, the expression fired for each record in the cursor, but didn't set the flag. When I then clicked the Print button from the preview window, it fired a second time for each record, and this time it did set the flag.

This is what you would expect, and what Mike Gangon said in his FAQ.

If it's not working for you, there must be some other reason. Perhaps the flag you are setting goes out of scope, or maybe something else. But basically the technique does work.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Hi Mike and Olaf,

thanks for your suggestions. I will go back and try again from scratch. This is a somewhat complicated report using many detail bands from different tables placed in multiple relationships prior to calling the report.

Could the complexity of the report have anything to do with this?

The DE of the report is empty with the relationships and "skip" settings being made before calling the report.

Thanks again
 
Mark,

I've made the same experience like you in the "on entry" / "on exit" expressions, but I can only repeat: Within report controls (not form controls) setting expression to sys(2040) does work for me.

Bye, Olaf.
 
Hi Olaf,

I've got a clue...but don't know how to deal with it.

I put execscript("glPrinted=(sys(2040)='2')") in the "on entry" in the first "gray" band of the report and ran it as above. I obtained my same result--the preview page showed correctly (without the print preview toolbar) but printing from it did not change the value of glPrinted.

Changing the reportbehavior to 80, caused the display to show only the print preview bar--not the report page. Clicking on the print icon printed the report AND changed the glPrinted variable to .t.

Hence, reportbehavior 80 and reportbehavior 90 do not run identically.

Is it possible the background form on which the report form is running is relevant? i.e., I am using a form as "top level" and have made _screen.visible = .f. The form being displayed when the report is called has showwindow = 1-in top level form, with a windowtype of 1-modal.

Very much thanks
 
Don't use the "on entry" property of a band. You noticed it does not work twice and I noticed too already. Forget about on entry.

Use the band itself. Put a control INTO the band. Set it's EXPRESSION to execscript(...). Or first start with sys(2040), so that it's really displayed WITHIN the band. Reportbehavior does not matter to me, it works with both 80 and 90.

You can later turn that report control invisible.

Report control means the controls you put into bands. Modify a report, then choose from the Menu: View->Report Controls Toolbar.
This toggles this toolbar to visible/invisible.

Toggle the toolbar to be visible. Within that Toolbar you choose the Field control (the rectangle with 'ab' inside it). Put that into the summary band. Then set this Field control's expression to SYS(2040) and it will display 1 in the preview and 2 in the printout. Set it to execscript() and it will run the glPrinted=(sys(2040)='2') 'script' and always display .T., but the variable glPrinted is then .F. in the preview and .T. in the printout and after the printout. Just define that variable glPrinted before running the report.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top