Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update an Access linked table to use a UNC path

Tags:

vba

ms-access

I have an Access 2010 database A.mdb with a list of tables, one of which is a linked table, linked from another Access database B.mdb on the same server. These databases are on a development machine xxx.xxx.xxx.xxx, which is mapped on my computer as R://, and they are afterwards published online on a yyy.yyy.yyy.yyy server.

If I want to work on the database locally, I need to change the link to the table. But if I change it via filesystem (using the "Linked Table Manager"), the link becomes R://.... and when I look at the ASP page that requests those data, it is broken because the path is wrong. Also, if I change the link locally, it won't work on the online server.

Is there a way to change the link "programmatically"? That is, without using the Linked Table Manager?

I searched for an answer, but I am not that expert, I just understood that I have to write a "Module"? "Macro"?

like image 699
Laura Silvani Avatar asked Mar 18 '13 09:03

Laura Silvani


People also ask

How do I use UNC path?

A UNC path uses double slashes or backslashes to precede the name of the computer. The path (disk and directories) within the computer are separated with a single slash or backslash, as in the following examples. Note that in the DOS/Windows example, drive letters (c:, d:, etc.) are not used in UNC names.

How do I get UNC path?

In Windows, if you have mapped network drives and you don't know the UNC path for them, you can start a command prompt (Start → Run → cmd.exe) and use the net use command to list your mapped drives and their UNC paths: C:\>net use New connections will be remembered.


1 Answers

Table links can be UNC paths. For example, say I have a linked table pointing to a database on \\192.168.1.2\Public\ which is mapped to drive P:. If I launch the VBA editor (Alt+F11), open the Immediate Window (Ctrl+G) and type...

?CurrentDB.TableDefs("remoteTable").Connect

...it will return...

;DATABASE=P:\B.accdb

...because I pointed to drive P: when I created the link.

Now if I create and run the VBA function...

Function linkToUnc()
Dim cdb As DAO.Database
Set cdb = CurrentDb
cdb.TableDefs("remoteTable").Connect = ";DATABASE=\\192.168.1.2\Public\B.accdb"
cdb.TableDefs("remoteTable").RefreshLink
Set cdb = Nothing
End Function

...the link is now a UNC path.

By the way, you can create UNC links in the Linked Table Manager if you browse to "Network", "machine name", "share name", but that will give you the machine name (in my case \\PICO\Public\B.accdb).

like image 141
Gord Thompson Avatar answered Nov 22 '22 05:11

Gord Thompson