Solved

how make a running total

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
indy tidtcpclient threading issue 8 65
tidtcpserver connection lost handle 2 72
creating threads in delphi 1 84
Dynamically Created Query 3 50
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now