Results 1 to 2 of 2

Thread: Linking tables to databases in code

  1. #1

    Thread Starter
    Junior Member OllieVB's Avatar
    Join Date
    Jan 2006
    Location
    England, UK
    Posts
    24

    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?
    Ollie
    Mess with the bull... You get the horns!
    ... Windows XP Home SP2
    ... Visual Basic 6 Professional Edition
    ... Office 2003 SP2 Professional Edition

    I will always leave a good response to helpful postings... They are a lifeline!

  2. #2
    Addicted Member
    Join Date
    Jun 2002
    Location
    Brugge, Belgium
    Posts
    208

    Re: Linking tables to databases in code

    Hello,

    There are a couple of possible solutions.

    You can code it through
    VB Code:
    1. 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width