Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set filter problem

Status
Not open for further replies.

zhed0708

IS-IT--Management
Jun 25, 2011
41
PH
how to use set filter....
i have a code in set filter but in the presence on the table..

LPARAMETERS tcFieldName, tcSearchText

SET FILTER TO && clear any previous filters

SET FILTER TO ALLTRIM(UPPER(&tcFieldName)) = ALLTRIM(UPPER("&tcSearchText"))

GO top
thisform.refresh()

i want to use set filter without the table...thanx..

zhed
 
What do you mean "set filter without the table"? A filter is on a table so you can't set one without having the table open.

Doug
 
LPARAMETERS tcFieldName, tcSearchText

SET FILTER TO && clear any previous filters

SET FILTER TO ALLTRIM(UPPER(&tcFieldName)) = ALLTRIM(UPPER("&tcSearchText"))

GO top
thisform.refresh()


Doug - I too was originally confused since a Filter HAS to have a table to work on.

But then I saw that, even though it was not presented clearly, it looks as though zhed wants to create a Form Method that can be called against a variety of tables.

So the Filter would not be without a table, but instead the method would not specifically SELECT the table since that would have to be Selected BEFORE the Form Method was invoked.

zhed - so what is your question?

Unless you are getting a specific error message that we can advise you about, just get the method to work through your own efforts.

Don't look to us to just give you line-by-line code.
That is what you can hire a VFP contractor/consultant to do.
We are here to suggest/advise when people have questions or specific problems.

Good Luck,
JRB-Bldr


 
So the Filter would not be without a table, but instead the method would not specifically SELECT the table since that would have to be Selected BEFORE the Form Method was invoked.

Well if that's the case, the obvious answer is to add IN (alias) to the command (as well as the GO TOP) and be done with it.

But it's reading an awful lot into what hasn't been posted.
 
My impression is that Zhed is looking for a generic way of setting a filter on any table. Rather than hard-coding the field name and the value, he wants to call a method which receives those items as parameters.

If that's right, it's hard to see any benefit in this. It's surely just as easy to say SET FILTER TO x = y than thisform.SetFilter(x, y).

However, if you really do want a separate method to do this, Zhed, then you need to pass a third parameters, this being the alias of the table in question. The code would then be something like this:

Code:
LPARAMETERS tcFieldName, tcSearchText[b], tcAlias[/b]
SET FILTER TO ;
  ALLTRIM(UPPER(&tcFieldName)) = ALLTRIM(UPPER("&tcSearchText")) ;
  [b]IN (tcAlias)[/b]

(By the way, you don't need to clear the previous filter. Issuing a new filter will automatically do that.)

But I really don't think this is a good way of going about things. It will limit your filter to a single "field = value" expression, plus it adds a level of obfuscation without any obvious benefit.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top