Subject Re: Preview.wfm and report printing
From Mervyn Bick <invalid@invalid.invalid>
Date Sat, 28 Oct 2023 11:16:19 +0200
Newsgroups dbase.getting-started

On 2023/10/27 17:18, trevor wrote:

> Mervyn,
> I've come across two problems.
>
> 1. on opening Repform.wfm
>   As printrans.rep sql still contains clause where transfer >= fdat1 etc
> set procedure to printrans.rep (in the 'onOpen event' of repform)
> results in "parameter not defined fdat1" as entryfields1&2 in repform
> are initially blank.  This seems like a circular problem .
>
> If I remove the where clause in sql I not sure what happens as I get
> error 2 which I assume is something else.

Open printrans.rep in the sourcecode editor.

Comment out any code you have in the header section to select records.

The code below the header section should look something like the
following.  Adjust the string for the sql property in the query's
constructor code if necessary.

local r
r = new printransReport()
r.render()

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


    this.TRANSPORT1 = new QUERY()
    this.TRANSPORT1.parent = this
    with (this.TRANSPORT1)
       left = 3540.0  //depends on placement and the metric used. Ignore
       top = 330.0
       width = 360.0
       height = 360.0
       sql = "select * from TRANSPORT.DBF where transfer >= :fdat1 and
transfer <= :tdat1"
       params['fdat1'] = {2001-01-01} //See below regarding format
       params['tdat1'] = {2001-12-31}
       requestLive = false
       active = true
    endwith

Note that the parameter names in the SELECT statement are preceded by
colons and parameter names are case sensitive.


As an aside, sql = "select * from TRANSPORT.DBF where transfer between
:fdat1 and :tdat1"  will also work and requires less typing. :-)

Don't set an index.  If you are using groups in the report (or simply
need to order the data) add an ORDER BY clause to the SELECT statement
using the appropriate fieldname.  Use multiple fieldnames if necessary
separated by commas.

sql = "select * from TRANSPORT.DBF where transfer between :fdat1 and
:tdat1 order by whatever,whatever1 "

The ORDER BY clause makes the rowset read-only but this is normally not
a problem for a report.

Make a note of the actual classname, the query's name and the parameter
names.

Use dates that will return a rowset containing some records.  These
dates are not important as they will be updated when the form is
launched. The date format on my computer is YYYY-MM-DD but you need to
use whatever is appropriate for your computer.

Close the sourcecode editor and double left-click on the report in the
Navigator.  The report should open with records for the dates supplied.

If the report opens correctly use the report name, the classname and the
parameter names in the launch form in the code I posted previously.

Mervyn.