This sample database shows how to query an external database "on the fly", that is, without linking any table of that external database to the current one. Instead, a SQL-string will be constructed that may be used from within code or that may be passed to i.e. a combobox or listbox.
The MDB allows you to choose a database-file and will then display all tables and/or queries therein. After choosing a table or query, all records will be pushed into a listbox (if possible).
This approach is most useful i.e. in scenarios where multiple backend-databases are being used. In such cases, using queries as tables (i.e., instead of tables) and simply modifying those queries' SQL-portion after the backend-database has to be changed will be way faster than using linked tables along with TableDef.RefreshLink.
This is one of the older entries that can also be found on the original Access-site.
Download: QueryOnTheFly_A2k.zip (46.34 kb)