Form: First record in Tabular-Type Form with change in Date?

ellusiveladyellusivelady Member Posts: 23
Hi,

Refer to link of image.

http://i267.photobucket.com/albums/ii28 ... marker.jpg

Both are screenshots of my problem; before and after.

The thing is that when I change my Starting Date, I want to point to the first record and reset all my prices.

I placed my coding under "Starting Date" - OnValidate().
MODIFYALL("Special Price (USD)",0);
MODIFYALL("Special Price (SGD)",0);
MODIFYALL("On Offer",FALSE);
RESET;

The funny thing is that when I change the date, all my prices will reset EXCEPT for the one that the pointer is at. ](*,) Refer to picture again; the bottom one.

I even tried changing the property SourceTablePlacement to First. Didn't help either.

Kindly advice anyone. Thanks. [-o<

Comments

  • garakgarak Member Posts: 3,263
    not reset use
    CurrForm.update(false);
    if find('-') then;
    
    [/code]
    Do you make it right, it works too!
  • ellusiveladyellusivelady Member Posts: 23
    Tried that too.

    Error Message...
    CurrForm.UPDATE cannot be called from here.

    I read the help guide. It says you cannot call update function at OnValidate trigger.

    I tried elsewhere. OnAfterValidate trigger. It works. But another message pops out.

    Message...
    Do you want to rename the record?

    I played around with it. Changed your code.
    OnAfterValidate trigger.
    CurrForm.UPDATE(true);
    

    Cause your code will cause the item to move to first line and overwrite the first record. I just want the pointer to be at first record.

    Kindly advice. Thank you for helping. =)
  • SiStSiSt Member Posts: 46
    [EDIT:]
    "Starting Date" is a table field? If not ignore my comment about the modify-trigger and try to set the values directly in the validate trigger.

    Have you tried to call FINDFIRST; in the OnAfterValidateTrigger?
    [/EDIT]

    The validate-trigger is called before the form modifies the record to the values that are currently stored in rec. Your modifyall statements will modify all records (including the current), but the modify called from the form will override the current record. The simple solution would be to use something like:
    MODIFYALL("Special Price (USD)",0);
    MODIFYALL("Special Price (SGD)",0);
    MODIFYALL("On Offer",FALSE);
    // RESET; 
    
    // Set values on rec:
    // (Using validate would be better, but modifyalls are also called without triggers)
    "Special Price (USD)" := 0;
    "Special Price (SGD)" := 0;
    "On Offer" := FALSE;
    

    BUT: I consider it bad style to change other records from inside the validate trigger. The validate trigger should test and ensure the integrity of the current record.
    You can use the modify trigger to update the values (rename-trigger if "Starting Date" is part of the primary key):

    if "Starting Date" <> Xrec."Starting Date" then begin
      MODIFYALL("Special Price (USD)",0);
      MODIFYALL("Special Price (SGD)",0);
      MODIFYALL("On Offer",FALSE);
    
      "Special Price (USD)" := 0;
      "Special Price (SGD)" := 0;
      "On Offer" := FALSE;
    end;
    

    Using the modify/rename-trigger you ensure that the values are only changed if modfiy is actually called (may, for example, not be the case if you call validate from inside your code and decide afterwards not to modify the record).

    Regards, Simon
  • DenSterDenSter Member Posts: 8,305
    what's the big deal about having the pointer at the first record? Did FIND('-') not work?
Sign In or Register to comment.