SETRANGE AND SORT MY RECORD OF DATATYPE CODE

Hello Friend am working on a report and i have a list of account numbers i want to setrange for to sort but am getting a run time error some assistance please

GLEntry.SETRANGE(“G/L Account No.”,‘100000’,‘199999’);
REPEAT
GLEntry.FIND(’-’);
UNTIL GLEntry.NEXT <= 0;

I think You Have to Correct Your Code …
i can Imagine that you are trying to SetRange of Dataitem Then you should be writing like below

GLEntry.SETRANGE(“G/L Account No.”,‘100000’,‘199999’);
IF GLEntry.FINDSET THEN
REPEAT
//Code to Loop
UNTIL GLEntry.NEXT = 0;

FIND(’-’) is an Old Syntax of Finding and always returns a set of records,in New NAV RTC
to get a set of records use FINDSET.
FINDFIRST – returns only one record i.e First
FINDLAST-- returns only one record i.e Last

Thank you Raja code runs but it is not doing what its supposed to that is to say it was supposed to only displace account number as per the range we set that is from ‘100000’ up to ‘199999’ it is showing even the account numbers of ‘410000’ hence it is not sorting out the account numbers properly

Raja’s code is fine. If it’s still returning account no. 410000, then you may not have set the setrange correctly. Can you show the new code you’re using?

This is the code

GLEntry.SETRANGE(“G/L Account No.”,‘100000’,‘199999’);
IF GLEntry.FINDSET THEN
REPEAT

IF GLEntry.“Global Dimension 1 Code”=‘002’ THEN BEGIN
GLEntry.RESET;
GovmentGran := GLEntry.Amount;
END
ELSE IF GLEntry.“Global Dimension 1 Code”=‘003’ THEN BEGIN
GLEntry.RESET;
GLEntry.GET(“Entry No.”);
LocalRevenue := GLEntry.Amount;
END
ELSE IF (GLEntry.“Global Dimension 1 Code” >= ‘100’) AND (GLEntry.“Global Dimension 1 Code” <= ‘199’) THEN BEGIN
GLEntry.RESET;
GLEntry.GET(“Entry No.”);
Donor:= GLEntry.Amount;
END
ELSE IF (GLEntry.“Global Dimension 1 Code” >= ‘200’) AND (GLEntry.“Global Dimension 1 Code” <= ‘299’) THEN BEGIN
GLEntry.RESET;
GLEntry.GET(“Entry No.”);
Projects := GLEntry.Amount;
END
ELSE IF (GLEntry.“Global Dimension 1 Code” >= ‘300’) AND (GLEntry.“Global Dimension 1 Code” <= ‘399’) THEN BEGIN
GLEntry.RESET;
GLEntry.GET(“Entry No.”);
Others := GLEntry.Amount;
END

UNTIL GLEntry.NEXT = 0;

Of course it doesn’t work. The primary function of the RESET function is to reset the filters. So what is that GLEntry.RESET and GLEntry.GET doing inside your loop?

Hello below is the code i am now using but it is still showing some account numbers in the range of 410000 so i am failing to get the reason okay more detail is i am using this code to pull a report so i put this code in G/L Entry, body (2) -OnPresection() could that be a problem ?

GLEntry.SETRANGE(“G/L Account No.”,‘100000’,‘199999’);
IF GLEntry.FINDSET THEN
REPEAT
IF GLEntry.“Global Dimension 1 Code”=‘002’ THEN BEGIN
GovmentGran := GLEntry.Amount;
END
ELSE IF GLEntry.“Global Dimension 1 Code”=‘003’ THEN BEGIN
LocalRevenue := GLEntry.Amount;
END
ELSE IF (GLEntry.“Global Dimension 1 Code” >= ‘100’) AND (GLEntry.“Global Dimension 1 Code” <= ‘199’) THEN BEGIN
Donor := GLEntry.Amount;
END
ELSE IF (GLEntry.“Global Dimension 1 Code” >= ‘200’) AND (GLEntry.“Global Dimension 1 Code” <= ‘299’) THEN BEGIN
Projects := GLEntry.Amount;
END
ELSE IF (GLEntry.“Global Dimension 1 Code” >= ‘300’) AND (GLEntry.“Global Dimension 1 Code” <= ‘399’) THEN BEGIN
Others := GLEntry.Amount;
END;
UNTIL GLEntry.NEXT = 0;

Hi,

You code looks fine as such. Although I would write it like this instead:

GLEntry.SETRANGE("G/L Account No.",'100000','199999');
IF GLEntry.FINDSET THEN
  REPEAT
    CASE GLEntry."Global Dimension 1 Code" OF
      '002' : GovmentGran := GLEntry.Amount;
      '003' : LocalRevenue := GLEntry.Amount;
      '100'..'199' : Donor := GLEntry.Amount;
      '200'..'299' : Projects := GLEntry.Amount;
      '300'..'399' : Others := GLEntry.Amount;
    END;
  UNTIL GLEntry.NEXT = 0;

But then again, not really sure what the code is doing on the OnPreSection trigger? That section is primarily used to control if the section should be displayed or not. And again, putting it here, then you are resetting the filter for ever record.

If you already have GLEntry as one of your dataitems in the report, then you should put the filter into the properties of the dataitem, then NAV will find the right accounts. Then put the “CASE … OF” statement (without FINDSET) into the OnAfterGetRecord trigger.

Hey Erik This solution was awesome now i am working on totals will let you know how am fairing Thankyou Really.