以编程方式更改链接表中的MS Access连接方式、链接、Access、MS

2023-09-08 11:09:09 作者:硪只是個放羊的小孩ゞ

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

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.

Changing链接表位置编程

Linked表中的MS Access 2010的改变连接字符串

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;"