以编程方式更改链接表中的MS Access连接 [英] Programmatically change the connection of a linked table in ms access

查看:202
本文介绍了以编程方式更改链接表中的MS Access连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经提到的其他网页我的问题,但我仍然无法得到这个工作。我觉得有点慢因为我有以下三个例子,但还是无法想出解决办法。

I have already referenced other pages for my problem but I still can't get this to work. I feel a bit slow given that I have three examples below and still can't figure this out.

<一个href="http://stackoverflow.com/questions/4928134/changing-linked-table-location-programatically">Changing链接表位置编程

<一个href="http://stackoverflow.com/questions/12606326/linked-table-ms-access-2010-change-connection-string?lq=1">Linked表中的MS Access 2010的改变连接字符串

<一个href="http://stackoverflow.com/questions/15473263/ms-access-2010-change-the-path-of-a-linked-table">MS进入2010 - 更改链接表的路径

下面是我使用的code:

Here is the code that I am using:

Dim tdf As TableDef
Dim db As Database
Set db = CurrentDb
Set tdf = db.TableDefs("DeviceListT")
tdf.Connect = "ODBC;DATABASE=" & CurrentProject.path _
                               & "\HarmonicProfileDatabase_be.accdb"
tdf.RefreshLink

现在的问题是,当我运行它会弹出一个窗口。

The problem is that when I run it a window pops up.

我不完全相信我所应该做的事与我也不希望它弹出摆在首位,因为我会给予的MS Access文件给别人,他们会不知道该怎么办这个窗口无论是。

I am not exactly sure what I am supposed to do with that nor do I want it to pop up in the first place as I will be giving the ms access files to someone else and they won't know what to do with this window either.

推荐答案

您正在使用SQL Server的参考,但链接的MS Access。对于MS Access,您不需要一个ODBC连接,只是引用数据库:

You are using SQL Server references but linking MS Access. For MS Access, you do not need an ODBC link, just refer to DATABASE:

DBFile = CurrentProject.path & "\HarmonicProfileDatabase_be.accdb
''Check the file exists
strFile = Dir(DBFile)
If strFile <> "" Then
    With CurrentDb
        For Each tdf In .TableDefs
            ''Check that this is a linked table
            ''It can be useful to use table of tables instead
            If tdf.Connect Like "*HarmonicProfileDatabase_be.accdb*" Then
                tdf.Connect = ";DATABASE=" & DBFile 
                tdf.RefreshLink
            End If
        Next
    End With
    MsgBox "Link HarmonicProfileDatabase_be.accdb" 
Else
    MsgBox "Problem"
End If

您也可以使用:

 sConnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" _
    & DBFile & ";Jet OLEDB:Database Password=pw;"

这篇关于以编程方式更改链接表中的MS Access连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆