Print Only last record.

zulqzulq Member Posts: 204
Hi,
Having problems print the last record of a report. The last record is printed but it is repeated equal to the number of records found in the source table. For example if there are ten records in the source table the last record will be printed ten times.
Below is the code am using to fetch the last record:
NRAPay.SETCURRENTKEY(RecordCount);
NRAPay.SETRANGE(RecordCount);
IF NRAPay.FIND('+') THEN BEGIN
CurrReport.SHOWOUTPUT; 
END ELSE CurrReport.SKIP;

Please help! ](*,)
Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?

Answers

  • suvidhasuvidha Member Posts: 117
    Hi...
    Just try it by removing first 2 lines...
    :!:
  • zulqzulq Member Posts: 204
    Thanks suvidha but your suggestion will not work. That is the criteria for getting the last record using the recordcount.
    Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?
  • matttraxmatttrax Member Posts: 2,309
    You have a couple solutions to your problem.

    One would be to maintain a variable called recIndex that increments everytime you go through the data item.
    OnAfterGetRecord:
       recIndex += 1;
    
    OnPreSection:
       IF recIndex = COUNT THEN
         CurrReport.SHOWOUTPUT := TRUE
      ELSE
         CurrReport.SHOWOUTPUT := FALSE;
    

    This is not very elegant and requires much more processing than is necessary. I would use a slightly modified version of what you have.
    Create a data item of type integer.
    
    OnPreDataItem:
      SETRANGE(Number, 1); //So we only go through once
      myRec.SETRANGE(myCriteria);
      IF NOT myRec.FIND('+') THEN
        CurrReport.BREAK;
    
    Add text boxes to the body of the Integer data item referencing your myRec variable fields that you want to display.
    

    Let me know if that doesn't make sense.
  • ufukufuk Member Posts: 514
    You can find the last record value in OnPreDataItem. Then you can compare this value OnAfterGetRecord with the passing records like (In your method you find the last record but it doesn't mean that it is the current record. ):

    OnPreDataItem
    NRAPay.SETCURRENTKEY(RecordCount);
    NRAPay.SETRANGE(RecordCount);
    IF NRAPay.FIND('+') THEN
    LastRecord:= NRAPay.RecordCount;
    NRAPay.RESET;(if necessary)

    OnAfterGetRecord
    CurrReport.SHOWOUTPUT := NRAPay.RecordCount = LastRecord;

    Ufuk
    Ufuk Asci
    Pargesoft
  • McClaneMcClane Member Posts: 40
    Or change the Sort Order in the Properties of your Data Item and set CurrReport.Break after the first record has been printed.
  • zulqzulq Member Posts: 204
    Thanks a lot all you guys...
    I have solved it and below is how I did it:
    OnPreDataItem:
    NRAPay.SETCURRENTKEY(RecordCount);
    NRAPay.SETRANGE(RecordCount); 
    IF NRAPay.FIND('+') THEN
    LastRecord := NRAPay.RecordCount;
    
    And OnAfterGetRecord:
    SETCURRENTKEY(RecordCount);
    SETRANGE(RecordCount,LastRecord);
    IF NOT FIND('+') THEN
    CurrReport.BREAK;
    
    Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?
Sign In or Register to comment.