Solved

how make a running total

Posted on 1998-04-16
4
176 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

15 Experts available now in Live!

Get 1:1 Help Now