Hi,
I am having trouble with the behavior of a form and a page.
I have added a field to the BOM Componet form, a decimal field, and then I want to show a total of the contents of that field on the bottom of the form.
On the form, I added a function that loops the BOM Components, and the function is called OnOpenform, OnAfterGetCurrRecord, OnBeforePutRecord, & OnNewRecord.
TotalCostPer := 0;
BOMComponent.COPYFILTERS(Rec);
IF BOMComponent.FINDSET THEN REPEAT
TotalCostPer := TotalCostPer + BOMComponent."Cost per";
UNTIL BOMComponent.NEXT = 0;
This correctly totals the field, and displays in the textbox at the bottom of the form.
I transformed the page, and it created 2 new functions on the page, OnAfterGetCurrRecord & OnBeforePutRecord.
When I run the page, and edit the new decimal field, and scroll to the next record, the total does nto update. But when I move back to the original line, the total appears to be correct.
So if the 3 lines are:
1
5
7.5
The total is 13.5.
If I change the 1 to 2, and move to the second line, the total should be 14.5 but it is still 13.5. If I move the cursor back to the first line, the total shows as 14.5, but then if I move it back it changes to 13.5.
There is similar code in the General Journal - but that works fine - is there some trick to dealing with the pages in this way? I hope I have explained this well enough.
-Andrew
As I said before, the code works fine on the form, but not the page.
0
Comments
uurrrghhh why are you doing this? Make life simple.
Move the code where it belongs into a function on the table.
Then add a control on the form using the function as the source. And get rid of all that useless onopen onafterget etc code.
You could do a couple of things, you could code as suggested. David is suggesting coding on the table and not the form as this is the recommended approach. code as much as possible in the tables and only go to the form if you have too (1 table can have multiple forms, so inherits code from the single table)
The other is you could do a self reflecting flowfield on the BOM Component table and show that at the bottom of the card. (no code)
Or add a Flowfield to the Item record and on the cards "GET" the item record in memory, calcfields on the new flowfield and show on the card.
t
I will do as suggested tomorrow - I was trying to make this as similar to the General Journal form - of course that was not coded with functions into tables... but I will see if that works.
Thanks,
Andrew
I moved my function to the table level - and it works fine at the form level, but I am getting the exact same issue at the page lavel, where I can scroll between records and have different values show up in my Total Cost field.
Any ideas?
Added a flowfield to the item table to sum the cost
Added a flowfield to the BOM Component table to sum the cost
Added a function to the BOM Component table to sum the cost
And all have the same issue, they do not properly update (as you can see from my two screenshots), as you move the cursor between the records, the function (leftmost value), updates when you go to the affected record (but not the other records), but the other values (flowfields) never update. I changed 18 to 19 in this example.
I sort of fixed this, OnValidate of the 'Cost per' field, I added the following code, which refreshes the form, and then all fields work on all records:
IF ISSERVICETIER THEN BEGIN
CurrForm.SAVERECORD;
IF ISCLEAR(WSHShell) THEN
CREATE(WSHShell,FALSE,ISSERVICETIER);
WSHShell.SendKeys('{F5}');
CLEAR(WSHShell);
END;
This does not seem like the best idea to me - if anyone is able to fix this without refreshing the form please let me know.
thanks,
Andrew