【发布时间】:2015-08-05 23:44:56
【问题描述】:
我将向 5-6 位客户销售基于 Access 的产品。哪里有后端数据库文件(受密码保护)。访问accdr前端文件,将数据保存在后端文件中。后端文件的位置会改变客户端到客户端,因此希望有一个链接前端和后端的 VBA 代码。
我试过下面的代码
sConnect = "Provider=Microsoft.ACE.OLEDB.12.0; " _
& Data Source= " & "C:\MyDB_be.accdb" & ";" _
& "Jet OLEDB:Database Password=123;"
但是,这些表没有重新连接。
我从this Ques on Stackoverflow 得到了上面的代码。
然后我尝试了下面的代码
Const LnkDataBase = "C:\MyDB_be.accdb"
Sub relinktables()
'Routine to relink the tables automatically. Change the constant LnkDataBase to the desired one and run the sub
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim strTable As String
Set dbs = CurrentDb()
For Each tdf In dbs.TableDefs
If Len(tdf.Connect) > 1 Then 'Only relink linked tables
If tdf.Connect <> ";DATABASE=" & LnkDataBase Then 'only relink tables if the are not linked right
If Left(tdf.Connect, 4) <> "ODBC" Then 'Don't want to relink any ODBC tables
strTable = tdf.Name
dbs.TableDefs(strTable).Connect = ";DATABASE=" & LnkDataBase
dbs.TableDefs(strTable).RefreshLink
End If
End If
End If
Next tdf
End Sub
当文件不受密码保护时,此方法有效。这段代码是我从This Ques 得到的。但没有规定密码。
请帮帮我。
要么指出第一个代码中的错误。或如何在中指定密码 第二个代码或新代码。
花了 4 小时寻找解决方案。访问 VBA 的新手。
【问题讨论】:
-
我试过
dbs.TableDefs(strTable).Connect = "Provider=Microsoft.ACE.OLEDB.12.0; " & "DATABASE= " & LnkDataBase & ";Jet OLEDB:Database Password=123;"但仍然无法让它工作。此代码给出错误。
标签: ms-access vba ms-access-2013