Solved

how make a running total

Posted on 1998-04-16
4
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

628 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