Reputation: 63
I have a grid on a form populated by a view. I added a button to filter the data.
cFilter = UPPER(ALLTRIM(INPUTBOX("Filter sur :","Spectech France - Suivi DDP")))
SELECT vwDdp_all
LOCATE FOR ALLTRIM(ref_client) = cFilter
IF FOUND()
SET FILTER TO ref_client = cFilter
THISFORM.grdDDP.Column10.SetFocus
ENDIF
I get a "Variable cFilter not found" error. What I don't understand is that the error comes after the above code has already run; and in the debugger, the guilty method is indicated as "MyForm.grdDDP". Nothing else. How can I find where it's actually looking for this variable?
Upvotes: 1
Views: 1952
Reputation: 23797
A filter expression must be visible at all times you navigate in the bound cursor. You could do:
Local lcFilter
lcFilter = Textmerge('ref_client = "<< m.cFilter >>"')
Set Filter To &lcFilter
BUT, set filter is one of the commands that almost all the developers have it on their "not to use" list. Especially with a grid, you shouldn't use "set filter". Instead you could simply use a query as the grid's source. Or if that ref_client is an indexed field then you could use "Set range" instead (it doesn't need a global variable or any & trick).
Upvotes: 1
Reputation: 418
The variable cFilter would have to be a global for your code to work.
If you don't want to use a global variable, you can do something like this.
cFilter = UPPER(ALLTRIM(INPUTBOX("Filter sur :","Spectech France - Suivi DDP")))
SELECT vwDdp_all
LOCATE FOR ALLTRIM(ref_client) = cFilter
IF FOUND()
lcFiltClause = [ref_client = ']+cFilter+[']
SET FILTER TO &lcFiltClause
THISFORM.grdDDP.Column10.SetFocus
ENDIF
Upvotes: 3