Access uber-noob here. Seriously - I'm just getting started with Access (this is my first database project, but I'm the most "qualified" guy in my office to take on this task). I can barely spell SQL, and yet I'm now trying to put together a series of queries to pull about a dozen tables' worth of data from 100+ little databases into one big database - and I'm really close to pulling this off! This is a one-shot deal, so I don't need an elegant or even particularly efficient solution here.
To make those records unique in the big database, I need to add a Unit (i.e. Office) Identifier to each record, since they will otherwise have duplicate values. I've got that part figured out, and I've even managed to set-up a combobox where I select the Unit ID from a list (and I'll repeat that process 100+ times as I connect to those external, individual databases and extract their records to put into the big database). And, I have written a teeny VBA module to execute a series of SQL queries to extract those records, add and populate the Unit ID field, and then push those records to the corresponding tables in the big database. But I need help to get one of those queries tuned-up so that it will insert the selected Unit ID into the filename when I refer to its external (individual) database.
So... In SQL for Access, how can I concatenate a string that specifies the path (fixed) and filename (corresponding to my selection of Unit ID via combobox from a list) for the external database that I want to extract records from using a SELECT FROM IN command?
Example:
External database is named xxyyy.mdb, where xxyyy is a Unit ID code
The path to xxyyy.mdb is C:\MyDatafiles\
Via a combobox selection in an objected named cbox0 on Form1, I have selected xxyyy from a table listing Unit IDs
I want to extract all records from xxyyy.mdb from a table named Locations in that external database
I want to put all those extracted records into a table named LocationsTemp in the active database
So, the hard-wired SQL statement, which currently works, looks like this:
INSERT INTO LocationsTemp
SELECT *
FROM Locations IN 'C:\MyDataFiles\xxyyy.mdb'[;];
But, I want that xxyyy part to be inserted into the SQL statement dynamically, so I want is something that looks like this:
INSERT INTO LocationsTemp
SELECT *
FROM Locations IN "'C:\MyDataFiles\" & [forms]![Form1]![cbox0] & ".mdb'[;];"
But, of course, that doesn't work, hence my inquiry here. I think there are 2 problems. First, I don't know how to tell Access that the stuff following IN is provided in the form of an expression, with concatenated bits composing the whole path and file name. Second, I'm not quite sure I'm "calling" the contents of the combobox selection with the proper syntax.
Thanks in advance!
SDL