Solved

how make a running total

Posted on 1998-04-16
4
180 Views
Last Modified: 2010-04-06
i have a master / detail form but i've a problem with showing a running total of a detail coloumn ( total ).
i've tried using onDataChange event but it doesn't work .
Please Help me
0
Comment
Question by:delphyst
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:d4jaj1
ID: 1361610
Did you reject my answer because it was wrong or because you couldn't see it?  I answered this question when the EE was having all of their problems. (I don't see the answer I posted either.  If you didn't get a chnace to see the answer - I'll post it again and you can grade it.  What you're trying to do isn't hard.  Let me know.  Jay.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361611
OK, explain what you really want....

1. You can use sql with sum function
2. You can calculate them yourself, after each change in data...

Regards, Zif.
0
 
LVL 3

Accepted Solution

by:
d4jaj1 earned 50 total points
ID: 1361612
I posted the inital answer when teh EE was having server problems.  I'll go ahead an repost the same answer since I don't see it above.  If it's not correct, Delphiyst can say so.

I've found it's best to add/sum values in a detail table when two events occur 1) when the master record changes or 2) you save a detail table.  Table1 below is teh master table & table2 is the detail.


procedure Tform1.Datasource1DataChange(Sender: TObject; Field: TField);
var
Count: Integer;
begin

if (table1.recordcount > 0) then
  Begin
    Count := 0;
    table2.disablecontrols;
    table2.first;
    while not table2.EOF do
      begin
      if table2.FieldByName('FIELD_TO_ADD').asInteger <> 0 then
       Count := Count + 1;
       table2.next;
      end;
      table2.first;
      table2.enablecontrols;
      label1.Caption := Inttostr(Count);
  end
else
 label1.Caption := '';
end;

procedure Tform1.table2AfterPost(DataSet: TDataSet);
var
Count: Integer;
begin
dbiSaveChanges(table2.handle);
Count := 0;
table2.disablecontrols;
table2.first;
while not table2.EOF do
  begin
    if tblHistory.FieldByName('FIELD_TO_COUNT').asInteger <> 0 then
       Count := Count + 1;
    table2.next;
  end;
table2.enablecontrols;
label1.Caption := Inttostr(Count);
end;
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361613
Hi d4jaj1,

Don't think your solution is wrong. Except, maybe ... You could have made a procedure which is called by the two events... Less code to write ;-). But I guess you know this already. ;-))))

C.u around Zif.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question