Announcements
Hi
How to read Data from Subform and then insert record in Same SourceTable or another table.
Thanks
*This post is locked for comments
What do you mean read the data from the subform ? From an action ? if so you need apply the same filters you have applied for subform link then get those records.
https://imgur.com/scLGnHa
I have Main Form (Location) & SaleDeposit SubForm (Source table is SaleDepositLines) . I have 1 Button . On Push Trigger of Button
I want those lines which have DepositAmount > 0 should be inserted in same table SaleDepositLines. I am trying below code but not working
CDLine refers to the same table which Subform refers to
CDLine.RESET;
CDLine.SETRANGE("Location.","No.");
CDLine.SETFILTER("Deposit Amount",'<>%1',0);
IF CDLine.FINDFIRST THEN BEGIN
REPEAT
CDLine.INIT;
EntryNo := EntryNo + 1;
CDLine.VALIDATE("Entry No.",EntryNo);
CDLine.VALIDATE("Location","No.");
CDLine.VALIDATE("Posted Amount", CDLine."Deposit Amount");
CDLine.INSERT;
UNTIL CDLine.NEXT = 0;
END;
Firstly why are you inserting the same records in the same table, and second your filter CDLine.SETFILTER("Receipt Amount",'<>%1',0) is looking for the lines which are not equal to zero for greater then you need to use CDLine.SETFILTER("receipt amount",'>%1',0); then in your REPEAT loop you need use another variable to insert the lines not the same variable which are looping may be call it CDLine2 and decalare it.
ok. In my scenario i am using only 1 table. That's why i have to do like this . If i was using 2 tables then it should not have been any issue
I am not asking to use two tables, create two different variables of the same table. One for looping and another for inserting. You cannot use the same variable to create and find. It will remove the filters you have applied.
Hi Suresh
I have change the code but it goes in infinite loop
CDNLine.RESET;CDNLine.SETRANGE("Location","No.");IF CDNLine.FINDLAST THEN EntryNo := CDNLine."Entry No.";
CDNLine.RESET;CDNLine.SETRANGE("Location","No.");CDNLine.SETFILTER("Receipt Amount",'>%1',0);IF CDNLine.FINDFIRST THEN BEGIN REPEAT
CDNLine1 := CDNLine; CDNLine1.VALIDATE("Entry No.", EntryNo); CDNLine1.VALIDATE("Location", "No."); CDNLine1.VALIDATE("Posted Amount", CDNLine."Receipt Amount"); CDNLine1.INSERT; CDNLine.VALIDATE("Receipt Amount", 0); CDNLine.MODIFY; UNTIL CDNLine.NEXT = 0;END;
You need to have a Boolean which you can set it to true once inserted into the table and while looping you will check only for false entries. Anyhow your logic of inserting the values into the same table based on a filter condition doesn’t make any sense.
What is your actual requirement ?
i have done like this . It is working Is it correct
CDNLine.RESET;
CDNLine1 := CDNLine;
CDNLine.SETRANGE("Location","No.");
CDNLine.SETFILTER("Receipt Amount",'>%1',0);
IF CDNLine.FINDFIRST THEN BEGIN
CDNLine1.VALIDATE("Entry No.", EntryNo);
CDNLine1.VALIDATE("Location", "No.");
CDNLine1.VALIDATE("Posted Amount", CDNLine."Receipt Amount");
CDNLine1.INSERT;
UNTIL CDNLine.NEXT = 0;
What you are doing is just creating duplicate entries, your whole logic is wrong. You need to specify what is your actual requirement and what are you trying to accomplish? If you want to find the entries with receipt amount greater then zero then you can retrieve those using filters why are you inserting it again in the same table?
Hi,
I've written a blog chrisdsilvablog.wordpress.com/.../how-to-update-the-selected-line-in-the-subform-on-click-of-an-action-button-in-the-mainform-in-nav
Hope it helps!
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
Jump in, show your community spirit, and win prizes!
Expanding mentorship, skilling, and AI innovation
These are the community rock stars!
Stay up to date on forum activity by subscribing.