Subject Re: Preview.wfm and report printing
From Mervyn Bick <invalid@invalid.invalid>
Date Tue, 31 Oct 2023 15:36:27 +0200
Newsgroups dbase.getting-started
Attachment(s) a_date_test.wfma_date_test.rep

On 2023/10/30 19:15, trevor wrote:
> Mervyn ,
>
> Both of your assumption are correct and  parameters added, clicking on
> report only works.
>
> I should have typed Pushbutton4_onclick1 in my message which is what I
> have on  my form correctly.
>
> Using newest preview.wfm but copied to my forms working directory so
> set procedure to Preview.wfm
>   ---not useing set procedure to :duflp:preview.wfm
>
> Preview  seems to be available as I can open preview if no onOpen
> event.Also that is how I have used previous versions.

Version 3.8 of preview.wfm uses message.wfm from the dUFPL.  Remember to
include message.wfo if you eventually build an EXE for your form and report.


>
> I have used all your suggested coding.
>
>
> I have checked several times for typos and can find none, those in my
> messages are down to lazyness :)
>
> Also as I have said I tried the onOpen event and pushbutton Onclick
> form.oPreview.open() with another simple no parameters report and get
> same error.
>
> Perplexed but grateful for your help.
>
> Trevor

Let's try with a report that works here.  If it works for you then
there's a gremlin in your code.  If it doesn't work for you then we'll
need to dig a bit deeper.

The attached test report uses the orders table in the DBASESAMPLES
sample database.  To check if this sample database was included with
dBASE 2.2  select the Tables tab in the Navigator and click on the down
arrow in the "Look in" combobox.  If the database is in the list select
it and see that the orders table is there.  If the database isn't there
have a look for a different samples database.  If it has the orders
table then you will need to edit the database object constructor code in
the report.

You will, in any event, need to edit both the report and the form to
change the default dates for the parameters and the entryfields to suit
the date format on your computer.

Before you run the form try the following.

Double left-click on the report in the Navigator.

In the Command Panel   do preview.wfm with 'a_date_test.rep'


Both should render the report showing date for January 2001 to February
2001.


Run the form and click the pushbutton.  This should open the report with
dates for January 2002 to March 2002 as set by the values in teh
entryfields.







** END HEADER -- do not remove this line
//
// Generated on 2023-10-31
//
parameter bModal
local f
f = new a_date_testForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class a_date_testForm of FORM
   with (this)
      onOpen = class::FORM_ONOPEN
      height = 16.0
      left = 20.0
      top = 3.2273
      width = 40.0
      text = ""
   endwith

   this.PUSHBUTTON1 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON1)
      onClick = class::PUSHBUTTON1_ONCLICK
      height = 1.6364
      left = 10.4286
      top = 10.8182
      width = 15.2857
      text = "Launch report in Preview"
   endwith

   this.ENTRYFIELD1 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD1)
      height = 1.0
      left = 19.8571
      top = 2.3636
      width = 12.4286
      value = {2002-01-01}
   endwith

   this.ENTRYFIELD2 = new ENTRYFIELD(this)
   with (this.ENTRYFIELD2)
      height = 1.0
      left = 20.0
      top = 4.6818
      width = 11.5714
      value = {2002-03-31}
   endwith

   this.TEXTLABEL1 = new TEXTLABEL(this)
   with (this.TEXTLABEL1)
      height = 1.0
      left = 7.2857
      top = 2.3636
      width = 12.0
      text = "Start date"
   endwith

   this.TEXTLABEL2 = new TEXTLABEL(this)
   with (this.TEXTLABEL2)
      height = 1.0
      left = 7.4286
      top = 4.6818
      width = 12.0
      text = "End date"
   endwith

   function PUSHBUTTON1_onClick()
      form.oRep.orders1.params['fdat1'] = form.entryfield1.value
      form.oRep.orders1.params['tdat1'] = form.entryfield2.value
      form.oRep.orders1.requery()
      form.oRep.pagetemplate1.text1.text = class::heading_dates()
      form.oPreview.viewer.ref = form.oRep
      form.oPreview.open()
      return

    function heading_dates
      nStartY = form.entryfield1.value.getYear()
      nStartM = form.entryfield1.value.getMonth()+1
      cStartM = form.aMonths[nStartM]
      nEndY = form.entryfield2.value.getYear()
      nEndM = form.entryfield2.value.getMonth()+1
      cEndM = form.aMonths[nEndM]      
      return cStartM+' '+nStartY+' to '+cEndM+' '+nEndY
      
   function form_onOpen()
      set procedure to preview.wfm
      form.oPreview = new previewForm()
      form.oPreview.bModal = true
      form.oPreview.bClose = false  
      set procedure to a_date_test.rep
      form.oRep = new a_date_testReport()
      form.aMonths = new array()
      form.aMonths.add('January')
      form.aMonths.add('February')
      form.aMonths.add('March')
      form.aMonths.add('April')
      form.aMonths.add('May')
      form.aMonths.add('June')
      form.aMonths.add('July')
      form.aMonths.add('August')
      form.aMonths.add('September')
      form.aMonths.add('October')
      form.aMonths.add('November')
      form.aMonths.add('December')
      return

endclass




** END HEADER -- do not remove this line
//
// Generated on 2023-10-31
//
local r
r = new a_date_testReport()
r.render()

class a_date_testReport of REPORT
   with (this)
      autoSort = false
   endwith

   this.DBASESAMPLES1 = new DATABASE(this)
   with (this.DBASESAMPLES1)
      left = 8415.0
      top = 555.0
      width = 360.0
      height = 360.0
      databaseName = "DBASESAMPLES"
      active = true
   endwith

   this.ORDERS1 = new QUERY()
   this.ORDERS1.parent = this
   with (this.ORDERS1)
      left = 2220.0
      top = 450.0
      width = 360.0
      height = 360.0
      database = form.form.dbasesamples1
      sql = "select * from orders where orderdate between :fdat1 and :tdat1 order by orderdate"
      requestLive = false
      params["fdat1"] = {2001-01-01}
      params["tdat1"] = {2001-02-28}
      active = true
   endwith

   this.PAGETEMPLATE1 = new PAGETEMPLATE(this)
   with (this.PAGETEMPLATE1)
      height = 16837.0
      width = 11905.0
      marginTop = 1080.0
      marginLeft = 1080.0
      marginBottom = 1080.0
      marginRight = 1080.0
      gridLineWidth = 0
   endwith

   this.PAGETEMPLATE1.STREAMFRAME1 = new STREAMFRAME(this.PAGETEMPLATE1)
   with (this.PAGETEMPLATE1.STREAMFRAME1)
      height = 11592.0
      left = 360.0
      top = 1365.0
      width = 9360.0
      form.STREAMFRAME1 = form.pagetemplate1.streamframe1
   endwith

   this.PAGETEMPLATE1.TEXT1 = new TEXT(this.PAGETEMPLATE1)
   with (this.PAGETEMPLATE1.TEXT1)
      height = 555.0
      left = 1200.0
      top = 480.0
      width = 4740.0
      prefixEnable = false
      fontSize = 14.0
      text = "January 2001 to February 2001"
      form.TEXT1 = form.pagetemplate1.text1
   endwith

   this.STREAMSOURCE1 = new STREAMSOURCE(this)
   with (this.STREAMSOURCE1.detailBand)
      height = 250.0
   endwith

   this.STREAMSOURCE1.detailBand.TEXTCUSTOMERID1 = new TEXT(this.STREAMSOURCE1.detailBand)
   with (this.STREAMSOURCE1.detailBand.TEXTCUSTOMERID1)
      height = 300.0
      left = 465.0
      top = 80.0
      width = 1170.0
      variableHeight = true
      prefixEnable = false
      alignHorizontal = 2        // Right
      text = {||this.form.orders1.rowset.fields["customerid"].value}
   endwith

   this.STREAMSOURCE1.detailBand.TEXTORDERDATE1 = new TEXT(this.STREAMSOURCE1.detailBand)
   with (this.STREAMSOURCE1.detailBand.TEXTORDERDATE1)
      height = 300.0
      left = 2880.0
      top = 110.0
      width = 1080.0
      variableHeight = true
      prefixEnable = false
      text = {||this.form.orders1.rowset.fields["orderdate"].value}
   endwith

   with (this.printer)
      duplex = 1        // None
      orientation = 1        // Portrait
      paperSource = 7
      paperSize = 9
      resolution = 3        // Medium
      color = 2        // Color
      trueTypeFonts = 1        // Bitmap
   endwith

   with (this.reportGroup.footerBand)
      height = 250.0
   endwith

   with (this.reportGroup.headerBand)
      height = 250.0
   endwith

   this.firstPageTemplate = this.form.pagetemplate1
   this.form.pagetemplate1.nextPageTemplate = this.form.pagetemplate1
   this.form.pagetemplate1.streamframe1.streamSource = this.form.streamsource1
   this.form.streamsource1.rowset = this.form.orders1.rowset

endclass