tags:

views:

1014

answers:

3

My scenario: Computer A has an Access database that contains linked tables. Those linked tables actually reside in another Access database on Computer B. Nothing unusual yet.

Now we create a SQL Server database, and establish links to those tables in the Access database on Computer B; we configure a Machine DSN to define the necessary ODBC connection on Computer B. Access database B now contains both local tables and linked SQL tables.

Access database A now wants to link to Access database B's new tables -- but only its local tables show up in the dialog to add a linked table. It appears that you can't "link to a linked table" in Access...

But is this actually true? What we want to do is present database B's SQL table links to database A as if they were local tables; i.e. database A is not aware that the new tables in database B are not actually local.

Of course, we could link the SQL tables directly into database A by configuring a DSN on that computer, but we don't want to do this. We would like to use computer/database B as a nexus or "gateway" that presents both local and SQL tables seamlessly to other Access client applications on the network. This is only a temporary setup that would allow us to gradually migrate all Access client apps to SQL Server-based tables, without having to modify a lot of code.

Can this be done? Is there another workable solution or scenario we haven't thought of?

A: 

Could you create a query/view on B that is just a view of the linked table on C, so that A can then access the query/view on B (which is actually the table on C)?

like:


Linked Query on A     ->     Query on B
                                :
                       Linked table on B     ->    Real table on C

edit after comment: OK, apparently you can't link to Queries, so that won't work then.

One other idea: Can you set up Replication between B and C so that all of C's tables are replicated to B, where A can access them?

codeulike
You can't link to queries...
DJ
What do you mean by "replication?" If you mean Jet replication, no, it doesn't work that way, and ODBC linked tables present several problems in a replicated MDB.
David-W-Fenton
Yes I meant Jet replication. OK looks like that idea isnt going to help either.
codeulike
+3  A: 

Nope - you can only link to real tables - you have to recreate the SQL server links you did on database B for database A

If the SQL server data does not change much and you are just using it for lookups you could import the data into real Access tables which you could link to.

EDIT

Another solution is to link the tables dynamically - that way you don't have to add the DSN manually to each computer. Use a connection string something like this:

ODBC;Driver={SQL Server};Server=<server name/IP>;Database=<database>;UID=<user>;PWD=<password>

This links a table

Dim db As Database
Dim TD As TableDef
Dim sTableName As String  ''MS Access name (can be same as SQL Server name)
Dim sServerTableName As String  ''SQL Server Name 

sTable = "Table1"
sServerTableName  = "dbo.Table1"
sServerConnect = "ODBC;Driver={SQL Server};Server=Localhost;Database=DB1;"

Set TD = db.CreateTableDef(sTableName)
TD.Connect = sServerConnect
TD.SourceTableName = sServerTableName

db.TableDefs.Append TD
db.TableDefs.Refresh
DJ
A: 

In regard to the query suggestion, it's possible to use an IN 'C:\OtherDatabase.mdb' clause in a FROM clause:

SELECT qryMyTable.* FROM qryMyTable IN 'c:\OtherDatabase.mdb';

This will display for you in the database where the query is stored the contents of the query in the other database. If that path to the other database doesn't change, you could use this method to piggyback on that other database's linked tables.

David-W-Fenton
This assumes the two databases share the same workgroup file.
onedaywhen
If they don't you can provide a full connect string with the appropriate authentication information and the appropriate workgroup file location.
David-W-Fenton
How do you specify the path to the workgroup file (mdw)? I gave up years ago after an Access MVP finally convinced me it wasn't going to be possible due to Jet's architecture. But if you know how to do it then I'd be delighted to learn. Tell you what: I'll start a new question on SO and you can earn some rep by answering it :) Watch this space...
onedaywhen
...done! Here: http://stackoverflow.com/questions/862803/specify-mdw-file-in-embedded-connection-string-to-another-jet-mdb-possible
onedaywhen
I saw your comment over there. So, are we agreed your answer here does assume the two databases share the same workgroup file?
onedaywhen
If you attempt to use a native Jet connect string, but if you use OLEDB (or possibly ODBC -- not sure on that one), you should be able to do it with different workgroups. It's a pretty far-out scenario all around, seems to me.
David-W-Fenton
Well, I can't put an OLE DB or ODBC connection string into the 'IN' into clause because the syntax is peculiar to the ACE/Jet engine. This was kind of a real requirement at the time: IIRC I was copying an auxiliary table (Calendar table perhaps?) to reuse it in another application's database. Sure, there are workarounds (e.g. linked table) but it got me curious about *why* this wouldn't be possible for ACE/Jet to do.
onedaywhen