Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sum grid column to form.text
Message
From
04/06/2000 22:19:46
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
04/06/2000 21:38:21
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00376579
Message ID:
00376592
Views:
29
>Hi,
>
>I need help, What I have a form that tracks customer insurance General data (name, address, Phone numbers, etc. etc.). It also has a grid on it, to track insurance coverage amounts. The grid gets its data from a table. Both are linked together Via S.S. Number. What I'm trying to do is display the sum of one of the columns (insurance coverage amount) in a text box on the from, but outside of the grid. The grid table data represents the child table, and the main form is the master table. Can anyone give me sample code of how to do this ?


John,
Keeping a few things in mind :
-Generally when parent rec changes data is updated (IOW child has tableupdated data which could be SQLed)
-Moving rec pointer in child using commands like sum, calculate etc are sometimes dangerous (I mean extra caution is needed)
-Sum only whould change if data contributing to its value changes (Insurance Coverage Amount -ICA field in your case)
It's easy and fast to do.

-Create a custom method (form or grid if that's a subclassed one) to do sum as 'parent' rec changes . It would just SQL sum child and store the value in 'total' textbox
-In ICA field's lostfocus (or valid if you prefer) update the textbox value with 'difference' of new value, old value.
*Custom sum method - call from anywhere that moves rec pointer in parent
external array mySum
select sum(ICA) from myChild ;
  where SSNum = myParent.SSNum ;
  into array mySum
thisform.TotalTxtBox.Value = iif(type('mySum[1,1]')='N',mySum[1,1],0)

*ICA filed grid textbox lostfocus
thisform.TotalTxtBox.Value = ;
  thisform.TotalTxtBox.Value - ;
  nvl(oldval('ICA','myChild'),0) + ;
  nvl(myChild.ICA,0)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform