Reputation: 1
I created a method that allow the user to filter data of a table by selecting different parameters from fields in a form.... The choices of the users are gathered and managed in 'cTextSearch' that change dinamically.
Now I would need to "copy" the data filtered in a cursor, in order to use the cursor in other parts of the program (ex. report).
HOW CAN I HAVE FILTERED DATA INTO A TEMP CURSOR WITHOUT BREAKING THE CODE?
So far I tested many ways and the only one which seems to work is the 'COPY TO' syntax... however, this creates me a new dbf file that is unwanted. The other syntax instead break the code. I also tried to use "SELECT.... INTO CURSOR..." but in these other cases the output was not the filtered table but the entire table.
When you check my code, I also used "COPY TO.." to dump the filtered data in an excel file. This is working until now, but it doesn't solve my issue.
Or the cursor is not behaving well or it didn't take the filtered data.
IF !EMPTY(cTextSearch) AND !bResetFilter
nOldWA = SELECT(0)
SELECT (cAliasName)
GO TOP
cCommand = "SET FILTER TO "+ cTextSearch
&cCommand
SELECT (cAliasName)
&© TO (cTempCursor) TYPE FOXPLUS
COPY TO (cCsvFile) TYPE CSV
SELECT(nOldWA)
ThisForm.bFilterOn = .T.
ENDIF
Upvotes: 0
Views: 289
Reputation: 3937
You can use SELECT ... INTO CURSOR, but as you've learned, it doesn't respect SET FILTER. So instead, you have to put your filter condition into the WHERE clause of the query.
Since your filter condition is in cTextSearch, try something like:
SELECT * ;
FROM YourTable ;
WHERE &cTextSearch ;
INTO CURSOR csrYourResults
Obviously, you need to substitute in the name of your table and the name you want for your cursor, and if you don't want to copy all fields, then list the ones you want instead of the asterisk in the first list.
Upvotes: 2