How to copy information from a table in a form?

Five
Member Posts: 32
Hello Navision People!
I have a problem where i run a form.It goes like this :
- a user inputs an item code into a textbox on the form and pushes a command button
- all records with the same itemcode then populate the grid of the form (or sourcetable).
- the user then modifies a field on those records say eg unit cost.
this is where i want to copy all the modified information to another table and clear the one in the form.
i have tried with the transferfields method but keep getting errors.here id the code:
ON PUSH
IF FIND('+') THEN
NextEntryNo :="Table Entry No." +1
ELSE
NextEntryNo := 1;
IF ItemCode <> '' THEN BEGIN
NewItemCode:= ItemCode;
INIT;
NewItemCode:=DELSTR(ItemCode,7);
Item.SETFILTER("No.",'%1',NewItemCode + '*');
IF Item.FIND('-') THEN
REPEAT
i+=1;
IF i=1 THEN BEGIN
IF Item."No." <> ItemCode THEN BEGIN
IF "Table Entry No."=1 THEN BEGIN
"Item No.":=Item."No.";
"Old price":=Item."Standard Cost";
Item.CALCFIELDS(Inventory);
Quantity := Item.Inventory ;
"Person Amending" := USERID;
Date := TODAY;
MODIFY;
//NextEntryNo:= NextEntryNo +1;
END;
END;
END ELSE BEGIN
"Table Entry No.":=NextEntryNo;
"Item No.":=Item."No.";
"Old price":=Item."Standard Cost";
Item.CALCFIELDS(Inventory);
Quantity := Item.Inventory ;
"Person Amending" := USERID;
Date := TODAY;
INSERT;
NextEntryNo:= NextEntryNo +1;
END;
//NextEntryNo:= NextEntryNo +1;
CLEAR(ItemCode);
RESET;
//END;
UNTIL Item.NEXT=0;
END;
table1.INIT; //table1 is an exact copy of the form source table
table1.TRANSFERFIELDS(table);
table1.MODIFY;
i keep getting the error that "table entry 0 already exits".
I set the delayed insert property to yes cos i want "TableEntryNo." to start at 1.
Thank you in advance for your help
I have a problem where i run a form.It goes like this :
- a user inputs an item code into a textbox on the form and pushes a command button
- all records with the same itemcode then populate the grid of the form (or sourcetable).
- the user then modifies a field on those records say eg unit cost.
this is where i want to copy all the modified information to another table and clear the one in the form.
i have tried with the transferfields method but keep getting errors.here id the code:
ON PUSH
IF FIND('+') THEN
NextEntryNo :="Table Entry No." +1
ELSE
NextEntryNo := 1;
IF ItemCode <> '' THEN BEGIN
NewItemCode:= ItemCode;
INIT;
NewItemCode:=DELSTR(ItemCode,7);
Item.SETFILTER("No.",'%1',NewItemCode + '*');
IF Item.FIND('-') THEN
REPEAT
i+=1;
IF i=1 THEN BEGIN
IF Item."No." <> ItemCode THEN BEGIN
IF "Table Entry No."=1 THEN BEGIN
"Item No.":=Item."No.";
"Old price":=Item."Standard Cost";
Item.CALCFIELDS(Inventory);
Quantity := Item.Inventory ;
"Person Amending" := USERID;
Date := TODAY;
MODIFY;
//NextEntryNo:= NextEntryNo +1;
END;
END;
END ELSE BEGIN
"Table Entry No.":=NextEntryNo;
"Item No.":=Item."No.";
"Old price":=Item."Standard Cost";
Item.CALCFIELDS(Inventory);
Quantity := Item.Inventory ;
"Person Amending" := USERID;
Date := TODAY;
INSERT;
NextEntryNo:= NextEntryNo +1;
END;
//NextEntryNo:= NextEntryNo +1;
CLEAR(ItemCode);
RESET;
//END;
UNTIL Item.NEXT=0;
END;
table1.INIT; //table1 is an exact copy of the form source table
table1.TRANSFERFIELDS(table);
table1.MODIFY;
i keep getting the error that "table entry 0 already exits".
I set the delayed insert property to yes cos i want "TableEntryNo." to start at 1.
Thank you in advance for your help

Compile and then Recompile ....
0
Comments
-
Hi, Five
1. Do you have a primary key of "Table Entry No."?
If yes then you should consider performing a LOCKTABLE before the NextEntryNo Assignement...
2. Where do you find the "ItemCode"? is it a field of Rec or a variable?
3. Why do you assign NewItemCode 2 times?
NewItemCode:= ItemCode;
INIT;
NewItemCode:=DELSTR(ItemCode,7);
4.What is "table" you use on the following lines?
table1.INIT; //table1 is an exact copy of the form source table
table1.TRANSFERFIELDS(table);
table1.MODIFY;
5. I advice you to make a temporary record variable (Temporary Property=Yes), Open the form with parameter this variable.
Then, when performing save, loop through all your temporary variable records and use the INIT, TRANSFERFIELDS and modify on a new record variable of your choise...
6. I think your code is a bit messy...
I hope I helped0 -
Guys,
Please use BBCode to format you code samples on the forum.
By this I mean putting "" (without spaces) and "[/code ]" (without spaces) around the C/AL Code sample. Then it will look like this: [code] IF YouGotAnIfStatement THEN YoullHaveToIndentYourCode := AndThisWillBeVisibleIfYouUseBBCode;
"Real programmers don't comment their code.
If it was hard to write, it should be hard to understand."0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions