Issue in Export to EXcel

Hi,

While exporting a report to excel, the following code is used in the OnPreDataItem() of the “Sales Invoice Header” table.

window.OPEN(Text001 + ‘@1@@@@@@@@@@@@@@@@@@@@@’);
window.UPDATE(1,0);
TotalRecNo := “Sales Invoice Header”.COUNTAPPROX;
RecNo :=0;

TempExcelBuffer.DELETEALL;
CLEAR(TempExcelBuffer);

ENTERCELL(1, 1, Text000, TRUE, TRUE, FALSE);
ENTERCELL(1, 2, Text002, TRUE, TRUE, FALSE);
ENTERCELL(1, 3, Text003, TRUE, TRUE, FALSE);
ENTERCELL(1, 4, Text004, TRUE, TRUE, FALSE);
ENTERCELL(1, 5, Text005, TRUE, TRUE, FALSE);
ENTERCELL(1, 6, Text006, TRUE, TRUE, FALSE);

row := 1;
RecNo := RecNo + 1;
window.UPDATE(1,ROUND(RecNo / TotalRecNo * 10000,1));
END;

Can anyone tell me what the “COUNTAPPROX” function do? What value does the ‘TotalRecNo’ variable field fetch the value. Coz its giving me a ‘Division By Zero’ of which the error points to the window.UPDATE line in the code.Its showing the ‘TotalRecNo’ value as 0 in the debugger.

Thanks in advance…

Use this function to obtain an approximate count of the number of records in the table, for example, for updating progress bars or displaying informational messages.

If a filter has been set on the record, this function will behave exactly as the Record.COUNT function.

Check for Filters and with Count also…

Hi Divyashree,

The CountApprox function is designed to be used in situations where the number of records in the table you’re counting is quite large and would otherwise take a considerable about of time if you were to use the Count function. The obvious tradeoff is precision. With CountApprox, you’ll get a number that approximates the actual count, but is not the exact number.

As a matter of practice, whenever I’m performing any processing that depends on the number of records in a table, I always add a test at the beginning to ensure that there are more than zero records to process. In your case, you might say something like …

if totalrecno <> 0 then begin

end;

By the way, I like that you’re assigning the result of SalesInvHeader.CountApprox to a variable rather than using the function in your Window.Update call. It saves you from having to count the recordset everytime your want to update the status bar. If you have some familiarity with the SalesInvHeader table and the record count, you may decide when writing the code to use the Count function rather than the CountApprox function - it’s just a tradeoff between speed and precision. The choice is yours to make.

Also, you might want to be aware that the mere process of updating a status bar puts a demand on the system. You can actually slow a long report considerably by displaying the update on every record. Once you see that you’re reporting on a very large number of records, you may chose to display the status update after every 10 records, or after every 100, depending on how large the database is. Just food for thought.