Not finding records in temp table

I have a many to many situation and need to get a single record (Document No. + posting date) for the multiple entries from the value entry table where journal entries used the same document no. I am not finding the original entry to be able to total the Cost posted to G/L value.
I am sure this is a simple thing but i cannot see what I am doing wrong.

(Dataitem = Value Entry)
clear(ValEntryTemp);
ValEntryTemp.SETCURRENTKEY(“Document No.”,“Posting Date”);
ValEntryTemp.SETRANGE(“Document No.”,“Document No.”);
ValEntryTemp.SETRANGE(“Posting Date”,“Posting Date”);
*IF ValEntryTemp.FIND(’-’) THEN BEGIN //*This is not working - not finding the first record
ValEntryTemp.“Cost Posted to G/L” := ValEntryTemp.“Cost Posted to G/L” + “Cost Posted to G/L”;
ValEntryTemp.MODIFY;
END ELSE BEGIN
ValEntryTemp.INIT;
ValEntryTemp.COPY(“Value Entry”);
END;

isn’t missing an insert ?

The COPY should insert the first record and then that record is modified by the next Value Entry record where the Document Number and Posting Date is the same. At least that is what I am trying to achieve.

Thanks Nuno, that was the answer.

I have now populated the table fields I need and then INSERT and all seems OK.

you are welcome [;)]

Only one advice

Use Transferfields instead of copy. Copy also copies filters from the other record and can lead to errors by excess of filters.
I don’t know you do that, but before using that temp table you should make a DELETEALL.

In general, copying filters should not be a problem if you have a good programming style (always using RESET (or clear),SETCURRENTKEY,SETRANGE/SETFILTER).

I even use tmpTemptable := “Value Entry”; and never had any problems.

The RESET+DELETEALL before filling up the temptable is a good programming style. So someone else sees immediately that the table is emptied at that point.

Don’t forget though (as I did recently) that := also copies the timestamp. So

That’s what an “equal” stands for [:D]

I was (happyly) surprised when I found out that the timestamp was “copied” too. But as I said: “equals”.