I have a Paradox table with 2 fields, both of type string.
The table looks something like this.
Code Detail
-------- ---------
1 Test
1 Cat
1 ATestB
1 TestC
2 Dog
2 Boat
2 Test
3 Frog
My problem occurs when I try to filter the tables using the filter property
of a TTable. I would like to filter on records that have any combination of
the word 'Test'
If I try to set the properties like this, either at design time or run-time:
Table1.Filtered := True;
Table1.Filter := 'Detail Like '%Test%';
I get an error, 'Filter Expression Incorrectly Terminated'
If the above filter worked the result would be:
Code Detail
-------- --------
1 Test
1 ATestB
1 TestC
2 Test
I would appreciate any help with this.
Thank's in advance.
--
Stefano
stef...@rainmaker.com.au.NOSPAM
"To filter strings bases on partial comparisons, use an asterisk as a
wildcard. For example: State = 'M*' "
I am not sure that "%" works. Also, if you are going to assign the filter
at run time you have to make sure that the string is enclosed in quotes.
Look at your original post. The first problem I see is that there are
three quotes. At a minimum you would need to have at least four (which
would work if the field you are filtering is a number), but in this case,
you need to show that the field is a string and you need to use 6 quotes.
So I am pretty sure your filter line should read:
" Table1.Filter := 'Detail Like ''*Test*'''; "
Once again, I am not sure if the "*" will work on both sides, but you can
try it.
Good luck.
Thanks for your suggestion, however I have tried all of that before, without
any luck. I think to get to the solution I want, I will have to change
tactic and solve it a different way.
Regards,
Stefano
-------------------------
>I have never tried to do exactly what you are doing, but I did take a quick
>look at the help file and here is a quote:
>
>"To filter strings bases on partial comparisons, use an asterisk as a
>wildcard. For example: State = 'M*' "
-------------------------
This is simply not valid syntax for a table's Filter property.
The syntax for filters is spelled out very explicitly in the printed
docs (as opposed to the online help, where all I see is a few examples).
There's no "Like" operator in TTable.Filter.
I imagine you could do something like this with a TQuery instead
(just a guess, I haven't got to TQuery yet). OR you could do it using
TTable.OnFilterRecord - this is much more flexible than TTable.Filter.
See the docs on OnFilterRecord - you'd want something like
Accept:= (Pos(FieldValues['Detail'], 'Test') > 0);
--
David Ullrich
sig.txt not found
Thanks for your suggestion. I tried it this morning and it worked like a
dream.
Stefano
David Ullrich wrote in message <351172...@math.okstate.edu>...
Fabulous. I suspected OnFilterrecord would do what you wanted.
But you should note I'm just starting the database stuff: if I got
the code for accessing the field value right it was by accident,
and even if it's right there may well be a more rfficient method
of doing that.
> David Ullrich wrote in message <351172...@math.okstate.edu>...
>
> > I imagine you could do something like this with a TQuery instead
> >(just a guess, I haven't got to TQuery yet). OR you could do it using
> >TTable.OnFilterRecord - this is much more flexible than TTable.Filter.
> >See the docs on OnFilterRecord - you'd want something like
> >
> >Accept:= (Pos(FieldValues['Detail'], 'Test') > 0);
> >
--