Topic: Print x Times , and every print is a page

Hi to all, I like your help. I have a excel file with 3 columns [ 1)Company, 2)Address, 3) x times]
What I want do is when I import  the file in the table grid and press the button Print it should print the row  so many times as the  in the 3 column of the excel file is (x times ). Every print should be one separate page.
Thank you in advance
***please feel free to correct my example

Post's attachments

Attachment icon printTimes.zip 334.75 kb, 235 downloads since 2019-12-03 

Re: Print x Times , and every print is a page

Check out

Post's attachments

Attachment icon printTimes_fixed.zip 7.87 kb, 272 downloads since 2019-12-03 

Dmitry.

Re: Print x Times , and every print is a page

Thank you!!!!!

4 (edited by v_pozidis 2019-12-09 09:23:10)

Re: Print x Times , and every print is a page

A quick an stupid question. How can I make a button of a preview screen?  When I tried it it shows me the previous recodrs.
Could you also explain me the procedure for the print , why do I need the temporary ?

Re: Print x Times , and every print is a page

But in the current project you already see a preview screen.



script with comments

procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
var
    Results: TDataSet;
    s1, s2, s3: string;
    i, iTimes: integer;
begin
    SQLExecute('DELETE FROM bc_temp'); // clear table from previous data
    SQLExecute('PRAGMA synchronous = OFF'); // to increase speed of INSERTs

    try
        SQLQuery('SELECT Company, Address, xTimes FROM BC', Results); // gets data from BC table
        while not Results.Eof do
        begin
            // read data
            s1 := Results.FieldByName('Company').asString;
            s2 := Results.FieldByName('Address').asString;
            s3 := Results.FieldByName('xTimes').asString;
            if s1 <> '' then s1 := '''' + escape_special_characters(s1) + '''' else s1 := 'NULL';
            if s2 <> '' then s2 := '''' + escape_special_characters(s2) + '''' else s2 := 'NULL';

            // how many times
            iTimes := 0;
            if ValidInt(s3) then iTimes := StrToInt(s3);

            // write data to bc_temp iTimes times for every record from "BC"
            for i := 1 to iTimes do
                SQLExecute('INSERT INTO bc_temp (Company, Address) VALUES ('+s1+','+s2+')');

            Results.Next;
        end;
    finally
        SQLExecute('PRAGMA synchronous = FULL');
    end;

end;

You must use temporary table (bc_temp), because report works only with data from database, so using this table we prepared data for this non standard report.

Dmitry.