You can get the list of open tables before a query with AUSED(), run query and get the second list. After that loop thtough the second array and close any tables/cursors that wasn't open before, excluding resulting cursor.
>When VFP asserts a SELECT-SQL statement with a table, it leaves the table open even if it was not already open. However, it does not put you in the workarea (or tell you the workarea) in which the table was opened. If you do SELECT from two tables with the same file name (different folders), then you end up with one alias named according to file name, and the other alias name is made up by VFP (an ABC letter). Lets assume that both of those tables need to be opened/accessed at the same time. The question then, when it's time for cleanup, is how to find those "Left-hanging-around" tables so you can explicitly close them.
--sb--