i would like to do something (update a table) when a report is printed from the preview windows.

the old way of setting a variable in the report and checking it afterward does not work with an object-assisted report because sys(2040) is not designed to work with the new behavior of the new reporting mechanism of vfp9.

llprinted = .f.
report form xxx to printer prompt object type 1
if llprinted
   ? "printed"

and in the report set llprinted to .t. if sys(2040)="2".  llprinted is always .f. even when the user prints the report.

after a few message exchanges with borislav borissov, cathy pountney, colin nicholls and agnes beste in ut, agnes pointed me to the direction of using the onpreviewclose event of the reportlistener to get the job done.  i have packaged the technique into a generic base class clsreport where different reports can be subclassed from.  the following code demonstrates the concept:

if not file('rptcustomers.frx')
   select 0
   use home(2)+'northwind\customers' shared noupdate again
   create report rptcustomers.frx from alias()

ox = createobject('clscustomersreport')
ox.icreportname = 'rptcustomers'
release ox

define class clsreport as session
   icreportname = ""
   function preview
      local lolistener as reportlistener
      lolistener = newobject('reportlistener')
      lolistener.listenertype = 1
      bindevent(lolistener,'onpreviewclose', this, 'onpreviewclose')
      report form (this.icreportname) object lolistener
      unbindevent(lolistener,'onpreviewclose', this, 'onpreviewclose')

   function onprinted()
   function onpreviewclose( tlprinted )
      if tlprinted

define class clscustomersreport as clsreport
   function onprinted()

please note that in this case the report is regarded as printed when it goes to the print spooler, even though it may not necessarily be physically printed (e.g. due to paper jam, user cancel print job, etc)


Leave a Reply

Your email address will not be published. Required fields are marked *