Trigger Problem for Filling a Temporary Table

tompynationtompynation Member Posts: 398
I got a problem for filling up a temporary table inside a subform... This temp table is the sourcetable from this subform

In my mainform i execute the following code:


Form - OnAfterGetRecord()CurrForm.GrondStofSamenStellingSub.FORM.SetProductCode(ID);
CurrForm.GrondStofSamenStellingSub.FORM.FillTempTable;

When i now switch from tabpage, this OnAfterGetRecord gets executed again. This leads to problems cause the FillTempTable get executed again


SetProductCode(ReceptID : Integer)
gv_ReceptID := ReceptID;

FillTempTable()
// Opvullen van Temp table
lv_ReceptItem.RESET;
lv_ReceptItem.SETRANGE(lv_ReceptItem.ReceptID,gv_ReceptID);
lv_ReceptItem.SETFILTER(lv_ReceptItem.ReceptItem,'<>%1','');
IF lv_ReceptItem.FINDFIRST THEN BEGIN
REPEAT
IF lv_Item.GET(lv_ReceptItem.ReceptItem) THEN BEGIN
Rec.Grondstof := lv_Item."No.";
Rec.Type := lv_Item."Item Category Code";
Rec.Omschrijving := lv_Item.Description;
Rec.Hoeveelheid := lv_ReceptItem.Hoeveelheid;
Rec.Percentage := lv_ReceptItem.Percentage;
Rec.INSERT;
COMMIT;
END;
UNTIL lv_ReceptItem.NEXT = 0;
END;

CurrForm.UPDATE(FALSE);


The FilltempTable creates an error cause it will insert duplicate values...

Comments

  • tompynationtompynation Member Posts: 398
    Now is there a way that i can fill the temp table only when the subform gets visible?

    So not in the onaftergetrecord of the mainform...
  • AlbertvhAlbertvh Member Posts: 516
    Hi
    Put your code in the AfterGetCurrRecord


    Albert
  • XypherXypher Member Posts: 297
    edited 2008-08-05
    Might I suggest you could have just edited your previous topic since this is the same issue. Have you tried using my suggestion?

    I think it would be rather simple to make a variable to store the current "ProductCode" and set it up so that if that same "ProductCode" is issued again, do nothing.


    But for starters, why separate the one function into two? You're calling both at the same place no matter what.
    Form - OnAfterGetRecord()
      IF ID <> varProductCode THEN BEGIN
        varProductCode := ID;
        CurrForm.GrondStofSamenStellingSub.FORM.FillTempTable(ID);
      END;
    
    FillTempTable(ReceiptID : Integer)
      lv_ReceptItem.RESET;
      lv_ReceptItem.SETRANGE(lv_ReceptItem.ReceptID,ReceiptID);
      lv_ReceptItem.SETFILTER(lv_ReceptItem.ReceptItem,'<>%1','');
    
      IF lv_ReceptItem.FINDSET THEN BEGIN
        REPEAT
          IF lv_Item.GET(lv_ReceptItem.ReceptItem) THEN BEGIN
            Rec.INIT;                 //<-- Looks like you were missing this...
            Rec.Grondstof := lv_Item."No.";
            Rec.Type := lv_Item."Item Category Code";
            Rec.Omschrijving := lv_Item.Description;
            Rec.Hoeveelheid := lv_ReceptItem.Hoeveelheid;
            Rec.Percentage := lv_ReceptItem.Percentage;
            Rec.INSERT;
          END;
        UNTIL lv_ReceptItem.NEXT = 0;
      END;
    
    CurrForm.UPDATE(FALSE);
    

    You don't need COMMIT since you're writing to a temporary table (aka not the actual database)
  • tompynationtompynation Member Posts: 398
    thanks the aftergetcurrrecord was what i needed \:D/
Sign In or Register to comment.