Function lj()
Dim catDB As ADOX.Catalog
Dim tblLink As ADOX.Table
Set catDB = New ADOX.Catalog
catDB.ActiveConnection = CurrentProject.Connection
Set tblLink = New ADOX.Table ' 建立一個新的表對象
With tblLink
.Name = "訂單" ' 鏈接表名稱
Set .ParentCatalog = catDB
.PropertIEs("Jet OLEDB:Create Link") = True
.PropertIEs("Jet OLEDB:Link Datasource") = _
"C:\Program Files\zhanyexing\123.mdb"
.PropertIEs("Jet OLEDB:Link Provider String") = _
"MS Access;PWD=123;" ' 提供者及密碼
.PropertIEs("Jet OLEDB:Remote Table Name") = "訂單" ' 原數據庫中的表
End With
catDB.Tables.Append tblLink ' 添加到庫中
Set tblLink = Nothing
End Function
注:在VBA編輯器中引用"Microsoft ADO Ext. 2.5 for DDL and Security"以及"Microsoft ActiveX Data Objects 2.1/2.5/2.6/2.7 Library"
以下是一段默認的 Access 的鏈接字串,以供參考
Provider=Microsoft.Jet.OLEDB.4.0;
User ID=Admin;Data Source=C:\Documents and Settings\ec\桌面\復件 db2.mdb;
Mode=Share Deny None;
Extended PropertIEs="";
Jet OLEDB:System database=C:\Documents and Settings\ec\Application Data\Microsoft\Access\System.mdw; Jet OLEDB:Registry Path=SOFTWARE\Microsoft\Office\10.0\Access\Jet\4.0;
Jet OLEDB:Database PassWord="";
Jet OLEDB:Engine Type=5;
Jet OLEDB:Database Locking Mode=1;
Jet OLEDB:Global Partial Bulk Ops=2;
Jet OLEDB:Global Bulk Transactions=1;
Jet OLEDB:New Database PassWord="";
Jet OLEDB:Create System Database=False;
Jet OLEDB:Encrypt Database=False;
Jet OLEDB:Don't Copy Locale on Compact=False;
Jet OLEDB:Compact Without Replica Repair=False;
Jet OLEDB:SFP=False