How to copy information from a table in a form?

FiveFive Member Posts: 32
edited 2004-03-30 in Navision Attain
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 :D
Compile and then Recompile ....

Comments

  • ArhontisArhontis Member Posts: 667
    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 helped
  • eromeineromein Member Posts: 589
    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."
Sign In or Register to comment.