MS Access模块

时间:2017-08-09 20:00:45

标签: vba ms-access

您好我对MS Access中的VBA编码相当新,我一直遇到数据传输模块的问题。我相信问题出在' DoCmd.RunSQL系列'但我无法确定如何解决它。代码如下:

    Public Function runit()

    DoCmd.TransferDatabase acLink, "Microsoft Access", "C:\Documents and Settings\LChristi\Desktop\Projections Sep 2013\2-Transpose and Break into Counties\2c-BreakIntoCountiesTransposed.mdb", acTable, "CNTY999", "CNTY999"

    cnty = Left(Right(CurrentDb.Name, 7), 3)

    DoCmd.RunSQL "insert into TBLCNTY" & cnty & " (UI, RU, Year, Month, County, NAICS, Owner, MEEI, Emp, AdjCnty, AdjNAICS, ADJEMP)Select UI, RU, Year, Month, County, NAICS, Owner, MEEI, Emp, AdjCnty,AdjNAICS,AdjEMP from CNTY" & cnty & "';"

    DoCmd.DeleteObject acTable, "CNTY" & cnty & ""

    End Function

当我尝试运行所述模块时,我收到错误' 3024'无法找回文件消息。此数据库已从一台计算机移至我的计算机。我想知道是否有人知道如何解决这个问题。

谢谢!

2 个答案:

答案 0 :(得分:1)

考虑一个纯SQL解决方案,因为Access可以使用内联调用从其他Access数据库进行查询。不需要DoCmd。*命令。此外,请务必转义等保留字。请填写以下位置:

INSERT INTO myLocalTable (UI, RU, [Year], [Month], County, NAICS, Owner, MEEI, Emp, 
                          AdjCnty, AdjNAICS, ADJEMP)
SELECT UI, RU, [Year], [Month], County, NAICS, Owner, MEEI, Emp, AdjCnty, AdjNAICS, AdjEMP 
FROM [C:\Path\To\External\Database.accdb].[myExternalTable] 

答案 1 :(得分:0)

“Documents and”中andSettings之间的文件路径中有一个双倍空格  设置“