How do I "chain" linked tables in Access? - ms-access

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?

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

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.

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?

Related

MS Access Link to Linked Tables in another databse [duplicate]

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?
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
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.
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?

Link Access Database with Mysql Server and Use Access as Frontend [Table Issue]

I was working on an Access Application that has already an access database (tables, queries etc ) and a front end. I was trying to link access existing database tables with mysql. So, what I have done so far is, I have successfully linked the access tables with mysql using ODBC. My understanding regarding linking access table with mysql db was that, by doing so, I would have the same 'old' access table linked with mysql, but I was wrong. Instead after linking I got a new table (fields same as old) that has links with mysql database.
http://i.imgur.com/mfSF5hR.png [See this link showing old 'access' and new 'linked' table]
For instance, I had an 'Actor' table in access db (before linking) and after it I have 2 tables. One is the old access 'Actor' table and other is the new linked table named 'Actor1'. So, if I do changes in my old access table, the table in mysql doesn't get change but when I do changes in my new linked table i.e 'Actor1' changes happen in mysql table too.
Here the problem is my front end form/queries are using my access table the old one, so is there any way to use new 'linked' table without changing in the front end ?
Thanks in advance.
You just need to rename your Linked MySQL table (rename the link in Access only) so that it matches perfectly the name you were using for that same table before in Access. This way you won't have to change your forms, queries, reports.
There is no magic that happens in Access between local tables and linked tables. It's still up to you to move your data, make sure the MySQL table is designed the way you want it, maintain the links, delete old Access tables, etc.

Joinning SQL Server table with *.mdb file

I'm trying to joinning SQLServer 2008 R2 tables with msaccess table (*.mdb).
I already tried "OPENDATASOURCE" and "Linked Server", but no one of them is work correctly.
in example, I've got the following message:
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server
"TestLinkServer" returned message "Cannot open database ''. It may
not be a database that your application recognizes, or the file may be
corrupt.".
the other error message:
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "MDBTest"
returned message "The Microsoft Jet database engine cannot open the
file '\10.55.56.34\Shared Folder\LBUS.mdb'. It is already opened
exclusively by another user, or you need permission to view its
data.".
and many more :D
can anyone give the working tutorial?
thanks in advance.. :)
The easiest way is to do the join inside ms-access.
Set up a table link in your access database that references the sql-server table you want to join.
Then build a query in access that joins that table with one or more tables in the access database.
If you want to join more than one sql-server table, first create a view in sql-server that combines all the relevant tables. Then set up your table link to reference the view.
If, for some reason, you must do the join inside SQL server, you will have to use a different technique, or use the table link feature to "push" data from the access table to a (previously defined) sql server table. Then, it's just an ordinary join.

How to retrieve the odbc database name of tables in ms-access VBA

I have a ms-access database and several ODBC linked tables in it.
As I have 2 set of ODBC database ,one is for production the other is for development, they have different names Development and Production.
How can I get the odbc info of the linked tables by using VBA?
Using the local name of the table, you can query the MSysObjects system table (typically hidden) for the table's Foreign Name.
SELECT MSysObjects.ForeignName
FROM MSysObjects
WHERE (((MSysObjects.Name)="LocalTableName"));
If you need more information about the foreign table, try your hand at parsing the 'Connect' column from the same table.
In fact, you can use ODBC to connect to the .mdb file as if it were an Access database. The linked tables will show up in that ODBC connection and be accessible at full ODBC speeds.
The nice thing about doing it that way is your program doesn't even have to know if the tables are linked tables or not. It's nice to contain all these sysadmin-level details in a single place.
My usual method of determining the source is to rename the tables, just like you would a native table. I may add a suffix or prefix such as tblTrombone_DEV and tblTrombone_PROD.

MS-Access Add Additional Linked Tables

I have an MS-Access database that was converted to use SQL Tables using the "Microsoft SQL Server Migration Assistant 2008 for Access" (aka SSMA) and created linked tables (so the MS-Access interface still works but is linked to SQL Tables).
Modifying those tables has been no problem (modify in SQL, use the Linked Table Manager in MS-Access, update tables). But I've not added a new table in SQL and I can't find a way to add that table to the set of linked tables.
I've tried the External Data -> ODBC Database, but it wants me to make a FileDSN and since the SSMA tool didn't require that I don't want to have some tables linked one way and other files liked another way (does anyone know how SSMA links the tables?).
So my underlying question is: Without using DSN how do I add an additional SQL Server table to MS-Access as a linked table?