Hi.
I need dynamicaly set several filter to one field.
I.e. sumary filter (values may be another)
myvar := 'VALUE1';
myvar := '';
myvar := 'VALUE2';
myvar := 'VALUE 3 BLANK';
SETRANGE(Field,myvar) - erase previous filter.
Doing
TextFilter += (myvar+'&');
SETFILTER(Field,TextFilter)
Then dificulty on checkin values with blank ''. Checkin if first value myvar<>'' (filter '&Value1&value2' wrong). Checking last value (then TextFilter += myvar, and not TextFilter += (myvar+'&');)
I can do it, but code is very bulky for that simple task.
May be somebody have a simple decision?
0
Comments
You can be inspired of code from Form 18 from function GetSelectionFilter which take all selected records and create the filter string for them. Automatically use .. or | based on selected records.
If you modify this code, you can use it for your need.
[Edited after posted]
Sorry... I forget that this code is not calculating with empty values.. ](*,) :-#
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Do checking of all empty values and replace them with string '%1'
Then do adding into one string...
use
It means that all %1 will be correctly replaced with empty string.
if the result is ''&VALUE2&VALUE3&'' is correct, ''&'' is equal to '' ('' is empty string) :-)
Have you fixed count of values or it is dynamic?
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
TextFilter += (myvar+'&'); \\wrong
TextFilter += (myvar+'|'); \\right
Count of values is dinamicaly changes.
Realy it deends on table SomeTable.
SomeTable.SETRANGE(Fild1,...)
SomeTable.SETRANGE(Fild2,...)
And all values SomeTable.Field3 is values for filtering second table.
REPEAT
TestFilter += SomeTable.Field3 +'|';
UNTIL SomeTable.NEXT =0;
SecondTable.SETFILTER(SomeField,TestFilter)
my corrected code for you:
another version
and another one:
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
And thanks to all who helped and writed here