Linking tables to databases in code
I have a database designed in Access 2003 for which I used the 'get external data' option to link (not import) data files. However, I would like to save the database 'unlinked' and have the code link the tables when it's run. This is so that when I run it on another machine, I can specify a path for where to find the tables with the database in runtime mode.
Can you help?
Re: Linking tables to databases in code
Hello,
There are a couple of possible solutions.
You can code it through
VB Code:
DoCmd.TransferDatabase acLink, "Microsoft Access", "c:\DatabaseToLinkTo.mdb", acTable, "Name of the table you want to link", "Name of the linked table in the current database"
or you can use a configuration file and use the directory in your SQL
for example
"select * from test in 'c:\test.mdb'"
Be careful when using joins and such as the in statement needs to be after the join.
eg
"select description from table1 inner join table2 on table1.id=table2.id in 'c:\test.mdb'"
So the 'c:\test.mdb' will reside either in an external file or in the database.
Kind regards,
Jason