Previous record in a form

dulamandulaman Member Posts: 73
Hi all,

I want to create a variable that shows the previous record value in a form.

I mean, something like this:
Field_1  myVar
111      Blank
112      111
113      112

I wonder if this is possible. I'm trying the NEXT(-1) function but no results until now.
Please note that I need myVar to be shown in a form because getting the trick in a report is easier.
-- dulaman
"I don't want to believe. I want to know." (Carl Sagan)

Answers

  • MTCMTC Member Posts: 159
    If I understand you correctly, create a variable of the same type as Rec.

    And place:

    prevRec := Rec;
    EXIT(NEXT(Steps));

    in the OnNextRecord trigger.

    prevRec will hold the values of the previous record.

    You should also place prevRec in the OnFindRecord trigger.
  • dulamandulaman Member Posts: 73
    Thank you MTC but my problem persists.

    I had already created a prevRec variable but I don't know how to use it in this context. :-(

    Anyway, if I place any kind of code in OnFindRecord or OnNextRecord triggers, my whole form stops working!
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
  • MTCMTC Member Posts: 159
    Another option is in the OnAfterGetCurrRecord trigger:

    prevRec := Rec;
    prevRec.NEXT(-1);

    This will get the literal previous record, the other example gives the previous displayed record.
  • dulamandulaman Member Posts: 73
    The previous displayed record is what I need! :-)

    But I still can't get the record I want because when I place your code in the OnNextRecord trigger, my form only shows one record and no more. And if I place your code in the OnFindRecord trigger, the form shows no record at all.

    Until now, I was placing my code in the OnFormat trigger of the previous column but I just got the literal previous record.
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
  • MTCMTC Member Posts: 159
    In the OnFindRecord you need:

    prevRec := Rec;
    EXIT(FIND(Which));

    In OnNextRecord:

    prevRec := Rec;
    EXIT(NEXT(Steps));

    Is this a list/table form or a card type form?
  • dulamandulaman Member Posts: 73
    It's a list/table form.

    My present code is:

    In OnNextRecord:
    prevRec := Rec;
    EXIT(NEXT(-1));
    

    In OnFindRecord:
    prevRec := Rec;
    

    About your code:
    prevRec := Rec;
    EXIT(FIND(Which));

    I am missing something in the OnFindRecord trigger, but what should I write in the place of 'Which' ?
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
  • AlbertvhAlbertvh Member Posts: 516
    Hi

    Do the following in OnAfterGetRecord() section

    MyRec.GET("No."); // Primary key field name(s)
    IF MyRec.NEXT(-1) = 0 THEN
      CLEAR(MyRec);
    
    

    where MyREc is Variable of Type Record

    Column in your list with SourceExp MyRec."No."

    Hope this helps
  • dulamandulaman Member Posts: 73
    Thank you Albert!
    Your code works fine -- but if I apply a filter, everything goes wrong. Alas, my form is entirely pointless if I am unable to filter it. :-(
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
  • AlbertvhAlbertvh Member Posts: 516
    Hi Fran,

    Before the MyRec.Get("no.") put


    Myrec.COPYFILTERS(Rec); :P


    Albert
  • dulamandulaman Member Posts: 73
    Hey! Thank you!! =D>

    But don't go too far -- maybe I need your wisdom once more ;-)
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
Sign In or Register to comment.