[AccessD] Adding a linked table in code

McGillivray, Don [IT] Donald.A.McGillivray at sprint.com
Thu Jun 5 13:17:14 CDT 2008


This seems like it ought to be simple, but I'm having trouble, and the Access "help" doesn't.  Running Access 2003 SP3.

All I want to do is to add a linked table to my db using code.  Here's what I have so far:

Dim db As DAO.Database, tdf As DAO.TableDef
Set db = CurrentDB()
With db
        Set tdf = .CreateTableDef("tblLocalTableName", dbAttachedTable, "tblRemoteTableName", _
            "D:\Path\RemoteDB.mdb")
        .TableDefs.Append tdf
        .TableDefs.Refresh
End With
Set db = Nothing

The error occurs on the "Set tdf . . . " line, and is "3001 - Invalid argument".

If I remove the Attributes argument (dbAttachedTable), I get an error on the ".TableDefs.Append" line, saying "3264 No field defined--cannot append tabeldef or index".

Seems like I ought to be able to tell it that I'm attaching to an existing table in an existing db, but obviously I'm doing something wrong here.  I've checked to be sure that the specified table exists in the remote db, and I've tried appending ";DATABASE=" to the connect string argument, all to no avail.

Any advice out there?


Thanks!

Don McGillivray





More information about the AccessD mailing list