Solved

how make a running total

Posted on 1998-04-16
4
181 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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…

809 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