我尝试使用以下语法将查询从一个数据库导入到另一个数据库:
strDbFile = "P:\Cadworx P&ID Implementation\3 Piping\P&IDs Jesus Test\Testproject\myTest.mdb"
strSourceTableName = "qryComponents_Process_Lines_Report"
DoCmd.TransferDatabase acImport, "Microsoft Access", strDbFile, acQuery, strSourceTableName, "Test", False
然而,当我这样做时,它会给我一个错误,指出找不到表或查询。我发现奇怪的是它没有我在运行TransferDatabase命令之前分配的名称。见下文。
答案 0 :(得分:1)
这是解决方案:
strSourceTableName = "Components-Process Lines" 'Source Table
strLinkName = "Components-Process Lines" 'Final table name once link has been established
strConnect = "MS Access;PWD=" & strPassword & ";DATABASE=" & strDbFile
Set dbs = CurrentDb
Set tdf = dbs.CreateTableDef
tdf.Connect = strConnect 'Establish link between databases
tdf.SourceTableName = strSourceTableName
tdf.Name = strLinkName
dbs.TableDefs.Append tdf
strSourceTableName = "qryComponents_Process_Lines_Report"
DoCmd.TransferDatabase acImport, "Microsoft Access", strDbFile, acQuery, strSourceTableName, "Test", False
我所要做的就是创建一个指向原始表的链接,源数据库中的查询来源于源查询(位于源数据库中)。完成此操作后,导入过程就成功了。