我只能使用VBscript。我的ACCESS数据库是2013版。
我有一个源MS Access数据库,其中包含一个名为“SourceTbl”的表。现在,我想编写一个vbscript,以便目标MS Access数据库可以创建一个“SourceTbl”的链接表。
我试图谷歌答案。但似乎不可能。有人可以帮忙吗?提前谢谢。
我尝试过的代码是使用DAO打开2个数据库,然后尝试使用docmd.transferdatabase和TableDefs.Append。但这两个属性似乎都无法在VBScript中使用:
strDbPath = "c:\temp\sourceDB.accdb"
Set dbe = CreateObject("DAO.DBEngine.120")
Set wrkJet = dbe.CreateWorkspace("", "admin", "", 2) ' dbUseJet = 2
Set db = wrkJet.OpenDatabase(strDbPath, True, False)
strDbPath2 = "c:\temp\destDB.accdb"
Set dbe2 = CreateObject("DAO.DBEngine.120")
Set wrkJet2 = dbe2.CreateWorkspace("", "admin", "", 2) ' dbUseJet = 2
Set db2 = wrkJet2.OpenDatabase(strDbPath2, True, False)
'I tried to use transferDatabase
dbe2.DoCmd.TransferDatabase acLink, "Microsoft Access", "c:\temp\sourceDB.accdb", acTable, "sourceTbl", "sourceTbl"
'Or use TableDefs, but both not work
db2.TableDefs.Append db.tabledefs("SourceTbl")
db.Close
Set db = Nothing
Set wrkJet = Nothing
Set dbe = Nothing
db2.Close
Set db2 = Nothing
Set wrkJet2 = Nothing
Set dbe2 = Nothing
**第2部分 - 我尝试使用“createTableDef”,但是,显示错误:“没有字段定义 - 无法附加TableDef或索引”
strDbPath = "c:\temp\sourceDB.accdb"
Set dbe = CreateObject("DAO.DBEngine.120")
Set wrkJet = dbe.CreateWorkspace("", "admin", "", 2) ' dbUseJet = 2
Set db = wrkJet.OpenDatabase(strDbPath, True, False)
strDbPath2 = "c:\temp\destDB.accdb"
Set dbe2 = CreateObject("DAO.DBEngine.120")
Set wrkJet2 = dbe2.CreateWorkspace("", "admin", "", 2) ' dbUseJet = 2
Set db2 = wrkJet2.OpenDatabase(strDbPath2, True, False)
set tdf = db2.createtabledef("sourceTbl")
tdf.connect = db.connect
tdf.sourcetablename = "sourceTbl"
db2.TableDefs.Append tdf
db.Close
Set db = Nothing
Set wrkJet = Nothing
Set dbe = Nothing
db2.Close
Set db2 = Nothing
Set wrkJet2 = Nothing
Set dbe2 = Nothing