# FieldRef.SetRange([Any] [, Any]) Method
> Version: _Available or changed with runtime version 1.0._
Sets a simple filter on a field, such as a single range or a single value.
## Syntax
```al
 FieldRef.SetRange([FromValue: Any] [, ToValue: Any])
```
## Parameters
FieldRef
Type: fieldref-data-type
An instance of the fieldref-data-type data type.
*[Optional] FromValue*
Type: ../any/any-data-type
The lower limit of the range. The data type of FromValue must match the data type of the field referred to by FieldRef.
*[Optional] ToValue*
Type: ../any/any-data-type
The upper limit of the range. If you omit this parameter, the FromValue you specified is used. The data type of ToValue must match the data type of the field referred to by FieldRef.
## Remarks
The SetRange method provides a quick way to set a simple filter on a field. If you call this method by using a field that already has a filter, that filter is removed before the new filter is set.
If you omit all of the optional parameters, all filters set for that field are removed. The SetRange method fails if no field is selected.
This method is like the ../record/record-setrange-method method.
## Example
The following example opens the Customer table as a RecordRef object, creates a reference to the first \(No.\) field, and stores the reference in the MyFieldRef variable. The SetRange method sets a filter that selects all records from 10000 to 40000 in the No. field. The ../recordref/recordref-find-method searches and selects the first record in the filter and counts the number of records that are found. The number of records is stored in the Count variable. The process is repeated by looping through all the records in the filter until no more records are found. The number of records that are found in the range is stored in the Count variable and displayed in a message box.
```al
var
    MyFieldRef: FieldRef;
    CustomerRecref: RecordRef;
    Count: Integer;
    Text000: Label '%1 records were retrieved.';
begin
    CustomerRecref.Open(Database::Customer);
    MyFieldRef := CustomerRecref.Field(1);
    MyFieldRef.SetRange('10000' , '40000');
    Count := 0;
    if CustomerRecref.Find('-') then
      repeat
        Count := Count + 1;
      until CustomerRecref.Next = 0;
    Message(Text000 , Count);
end;
```
## Related information
fieldref-data-type
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/fieldref/fieldref-setrange-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/fieldref/fieldref-setrange-method/
