>This line generates an error: No database is open or set as the current database (Error 1520). Please note that it is generated by the 2nd part, the INDBC() function. I used the 1st part, the DBUSED() function, to prevent that from happening.
yes, you are right, DBUSED() only tells you that the database is open. To determine if it is the current database use:
IF SET('DATABASE') != lcMyDatabaseName
SET DATABASE TO (lcMyDatabaseName)
ENDIF