How to display a 'running total' on a report preview AND on pdf/print?

amorosik

Member
Local time
Today, 14:59
Joined
Apr 18, 2020
Messages
548
I have a report that needs to display rows composed of a DARE field and a AVERE field, and a third field that I will call SALDO that contains the difference between DARE and AVERE added to the SALDO field of the previous row
A basic example is attached
There are global variables for the report that are incremented and decremented, and that are used to enhance the SALDO field of each row

In preview everything works correctly
With the preview open, if I try to create a pdf using the command button on the Access command bar, or start printing, the values are incorrect because the report variables are not reset to their initial value

The question is: having the preview open, how can I detect the start of the pdf creation or the start of the report printing in order to reset the variables and make the data appear correct also in pdf/print?
 

Attachments

Is there a report on print event that you can use to reset your internal counters.

I understand the issue, but I can't recall how I fixed the same problem.
 
No, I have already tried on ALL events (at least on Report object) and no event is called at the time of PDF creation
Or at least with the normal breakpoint on the classic Debug.print the code does not stop
 
Access always requeries the recordset and regenerates the report before printing the report. That means that YOU are responsible for initializing all variables used in calculations.

You're going to have to add a
MyVar1 = 0
MyVar2 = 0
MyVar3 = 0
To the first piece of code that updates the variables when the report opens.

VBA doesn't require variables to be initialized. It does it for you but ONLY if they are not already initialized by your code which in this case isn't very helpful to you.
 
I have a report that needs to display rows composed of a DARE field and a AVERE field, and a third field that I will call SALDO that contains the difference between DARE and AVERE added to the SALDO field of the previous row
A basic example is attached
There are global variables for the report that are incremented and decremented, and that are used to enhance the SALDO field of each row

In preview everything works correctly
With the preview open, if I try to create a pdf using the command button on the Access command bar, or start printing, the values are incorrect because the report variables are not reset to their initial value

The question is: having the preview open, how can I detect the start of the pdf creation or the start of the report printing in order to reset the variables and make the data appear correct also in pdf/print?
I’m not in a position to open the Access file but wonder if you considered using the running sum property of textbboxes rather than using code?
 
maybe you can use Temporary table.
i added tables:
1. DatiPrecedenti - you put here the previous values for DARE and Avere.
2. TempTabella - this is used by the report. On the Open event of the Report (rtpTest1), using
VBA this table got filled with records.
 

Attachments

Access always requeries the recordset and regenerates the report before printing the report. That means that YOU are responsible for initializing all variables used in calculations.

You're going to have to add a
MyVar1 = 0
MyVar2 = 0
MyVar3 = 0
To the first piece of code that updates the variables when the report opens.

VBA doesn't require variables to be initialized. It does it for you but ONLY if they are not already initialized by your code which in this case isn't very helpful to you.

Maybe you didn't understand what I asked, or maybe I didn't explain well
I have a report that displays data taken from a table
Some variables defined globally at the report level are initialized on Report_Open, one of these variables is 'saldo_totale_corrente'
One of the fields in the body, the txtSaldoRiga textbox is valued by code, in the Detail_Form event, using the 'saldo_totale_corrente' variable and some counts performed with values from the db
The problem is that the report variables are not reset when I start the PDF creation or I start the print
And therefore incorrect values appear on the PDF created or the print

The question is: having opened the report preview (and therefore having already set the report variables to their initial values in Report_Open), how can I set the report variables to the initial values when I start the PDF creation/print?
 
maybe you can use Temporary table.
i added tables:
1. DatiPrecedenti - you put here the previous values for DARE and Avere.
2. TempTabella - this is used by the report. On the Open event of the Report (rtpTest1), using
VBA this table got filled with records.

Yes of course, thank you very much for the example proposed
Base the report on all fields linked to the table is certainly a possible choice (temporary data update times permitting)
But it is really strange to think that via code this cannot be done
 
The problem is that the report variables are not reset when I start the PDF creation or I start the print
And therefore incorrect values appear on the PDF created or the print
I understand the problem. I explained why that happens.

Try using the temp table if you can't find an event that works to reset the initialization.
 
If you can't find a fix you could tell your users not to preview the report first, or to rerun it without the preview.
 

Users who are viewing this thread

Back
Top Bottom