I've created a Movement Worksheet and on a button click I want it to transfer all the records in the current worksheet into the new one.
What's the most efficient way to do this?
*This post is locked for comments
Sorry for being Vague, issue has been resolved!
Didnt get.. can you show us screenshot with issue..
The soloution appears to work, thank you. On the Worksheet when you press the button, all the records from the new worksheet appear on the page, if you close and reopen it they dispear, as if it's showing the new journal, however the headings still show the old one. Is it possible to prevent this?
My apologies didn't see last line of your reply, ill try new soloution
Please remove the Line No. filter from above code..
recShortageWorksheet2.SETRANGE("Line No.", recShortageWorksheet2."Line No.");
It's still not finding the correct Line number and updating it with + 10000
recShortageWorksheet2.RESET;
recShortageWorksheet2.SETRANGE("Worksheet Template Name", 'MOVEMENT');
recShortageWorksheet2.SETRANGE(Name, 'SHORTAGE');
recShortageWorksheet2.SETRANGE("Location Code", 'TIOGA');
recShortageWorksheet2.SETRANGE("Line No.", recShortageWorksheet2."Line No.");
IF recShortageWorksheet2.FINDLAST THEN
recShortageWorksheet2."Line No." := recShortageWorksheet2."Line No." + 10000
ELSE recShortageWorksheet2."Line No." := 10000;
recShortageWorksheet2.SETRANGE("Worksheet Template Name", recShortageWorksheet2."Worksheet Template Name");
recShortageWorksheet2.SETRANGE(Name, recShortageWorksheet2.Name);
recShortageWorksheet2.SETRANGE("Location Code", recShortageWorksheet2."Location Code");
I prefer to use Hardcoded values like MOVEMENT, SHORTAGE etc. instead of recShortageWorksheet2.Name .
please try and let us know.
Please dont add Line no. filter in above code.
Taking this Code. I'm attempting to filter through the new record that the Records being transferred to. When trying to find the Last Line In the New record it's not finding the right value and trying to assign the new record to the same line No. How can I ensure it's finding the last line No. (I've taken it out of a repeat loop just to avoid infinite loops for now. )
Rec.RESET;
recShortageWorksheet.RESET;
IF Rec.FINDSET THEN BEGIN
// Transfer Records Into New Worksheet
recShortageWorksheet.INIT;
recShortageWorksheet.TRANSFERFIELDS(Rec);
recShortageWorksheet."Worksheet Template Name" := 'MOVEMENT';
recShortageWorksheet.Name := 'SHORTAGE';
recShortageWorksheet."Location Code" := 'TIOGA';
recShortageWorksheet."Line No." := recShortageWorksheet."Line No.";
recShortageWorksheet2 := recShortageWorksheet;
// Find the Last Line No.
recShortageWorksheet2.RESET;
recShortageWorksheet2.SETRANGE("Worksheet Template Name", recShortageWorksheet2."Worksheet Template Name");
recShortageWorksheet2.SETRANGE(Name, recShortageWorksheet2.Name);
recShortageWorksheet2.SETRANGE("Location Code", recShortageWorksheet2."Location Code");
recShortageWorksheet2.SETRANGE("Line No.", recShortageWorksheet2."Line No.");
IF recShortageWorksheet2.FINDLAST THEN
recShortageWorksheet2."Line No." := recShortageWorksheet2."Line No." + 10000
ELSE recShortageWorksheet2."Line No." := 10000;
// Insert New Records into New Worksheet.
recShortageWorksheet2.INSERT;
DELETE;
//UNTIL Rec.NEXT = 0;
END;
Thanks
[quote user="LewisTioga"]
I Have this code so far. When it reaches the IF recShortageWorksheet2. FINDLAST THEN and the line below the value of the Name changes from SHORTAGE to the previous value 'AUTOMOVE' and is therefore inserting the new records into the old table. How do I resolve this?
Rec.RESET;
IF Rec.FINDSET THEN REPEAT
// Transfer Records Into New Worksheet
recShortageWorksheet.INIT;
recShortageWorksheet.TRANSFERFIELDS(Rec);
recShortageWorksheet."Worksheet Template Name" := 'MOVEMENT';
recShortageWorksheet.Name := 'SHORTAGE';
recShortageWorksheet."Location Code" := 'TIOGA';
recShortageWorksheet."Line No." := recShortageWorksheet."Line No.";
recShortageWorksheet2 := recShortageWorksheet;
// Find the Last Line No.
IF recShortageWorksheet2.FINDLAST THEN
recShortageWorksheet2."Line No." := recShortageWorksheet2."Line No." + 10000
ELSE recShortageWorksheet2."Line No." := 0;
recShortageWorksheet := recShortageWorksheet2;
// Insert New Records into New Worksheet.
recShortageWorksheet.INSERT;
UNTIL Rec.NEXT = 0;
[/quote]
You need to check this code as you are assigned recShortageWorkSheet2 to recShortageWorkSheet after findlast and then you are inserting the record. Activate Debugger and check
recShortageWorksheet2 := recShortageWorksheet;
// Find the Last Line No.
IF recShortageWorksheet2.FINDLAST THEN
so you are doing it to append the lines to new movement worksheet if there are any lines alreaddy exists. right?
you can add filters instead of assigning the code.
recShortageWorksheet2..SETRANGE("Worksheet Template Name",TO worksheet templte name);
recShortageWorksheet2.SETRANGE(Name,TO worksheet name);
recShortageWorksheet2.SETRANGE("Location Code",To Worksheet location);
IF recShortageWorksheet2.FINDLAST THEN
...............
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156