I have finished coding the solution. I ended up using DAO after all.
The solution grabs a collection containing info about the source and target database paths and table names.
Then it loops through the collection, opens the target database, deletes the table if it exists there, then runs a query using the “IN” clause to pull the table from the source database.
Here’s the main function:
As you can see, I’m delegating to a few other functions. The first grabs the collection with all the information. It uses a collection I can loop through. Each element of the collection is a simple Class containing just public string variables so I can get names that make sense.
And here is the GetTableCollection function:
Then I use another function to add the TableToCopy objects to the collection. This function takes the collection to add to, the source db, the target db and an array of table names. Even though I made this a function, it should have been a sub because I don’t return anything. I simply add to the collection it was given.
After getting the collection, I loop through it, open the target db and delete the target table if it exists using this sub:
The sub above loops through all the tables in the database and deletes the table name if it’s found in the TableDefs collection.
Finally, the original function then runs a SQL statement in the form of SELECT * INTO localtable * FROM srctable IN ‘srcDbPath’. This connects automatically to the remote srcDbPath table, kind of like a linked table, but you don’t have to actually create a link.
That’s it. There’s a few things you could do to this code to make it better. Like I’m only defining one table name for both the source and target tables, although you could change the AddTablesToCollection function to fix that. It also does absolutely no error checking. If it does encounter errors it will pop up the standard dialog. It will not be very graceful if you put the wrong paths in, or the paths are a UNC that is currently unavailable, or you put in the wrong table names.
But it does work for my purposes and in testing performed it’s function.
Now on to another task!
10/10/24 – Added Part 3!