Martinmcc,
I do this kind of thing all the time. Fox has something called Macro Substitution that makes this possible. I'll make an example below, with a couple of items.
Usually what I do, is set my "Seed" value to something that will be constant, generic, and "Add-able on-able".
lcSelectStatement = " * FROM MyTable INTO CURSOR"
*
* then, I might add logect to see if I have anything to add
*
IF NOT EMPTY(lcCriteria1) OR NOT EMPTY(lcCriteria2)
lcSelectStatement = lcSelectStatement + " WHERE "
ENDIF
*
* then, tack on the criteria...
* in the example below, assume lcCriteria1 is "Customer.CUID = lcCUID"
*
IF NOT EMPTY(lcCriteria1)
lcSelectStatement = lcSelectStatement + lcCriteria1
ENDIF
*
* then, tack on some more, if it exists...
* assume lcCriteria2 is " AND lcLname = 'Smith'"
*
IF NOT EMPTY(lcCriteria2)
lcSelectStatement = lcSelectStatement + lcCriteria2
ENDIF
*
* Now this next bit is subtle, but significant.
* when macro-subbing on a Select, I still like to "Show"
* the main "Command" in code, so that it is easy to follow.
* So, instead of making the next statment a Macrosub
* holding the whole value, I prefer this syntax:
SELECT &lcSelectStatement
*
*
This way, you can *EASILY* see what is really taking place. You are using a SELECT, with the criteria substituted. When I see a Macro Sub like this as well, it lets me know that I have a dynamic criteria on that Select statement.
Play with this. There is virtually no bounds by which you can customize, modify it to your needs/liking.
Thanks,
-Scott
Please let me know if this has helped! s-)