错误2465无法找到字段' | 1'在你的表达中提到

时间:2016-09-13 16:45:46

标签: access-vba ms-access-2010 runtime-error

我创建了一个我想要的查询。然后,我查看了Access中的SQL View窗口,以复制/粘贴到VBA中。我唯一改变的是" WHERE"包含自动编号ID的部分(此处称为num_PM,这是表单中的文本框)我已经看了一段时间,我无法看到我做错了什么。我现在正在接受

  

错误2465无法找到字段' | 1'在你的表达中提到。

Set rst_UnitEntryCounts = CurrentDb.OpenRecordset("SELECT tbl_UnitTypes.UnitTypes_WeeklyTextBoxUserEntryForm, " _
                                                    & "        tbl_UnitTypes.UnitTypes_CumalativeTextBoxUserEntryForm, " _
                                                    & "        tbl_PMEntry.PMEntry_Week_Ending, " _
                                                    & "        Sum(tbl_UnitEntry.UnitEntry_Unit_Count) AS SumOfUnitEntry_Unit_Count " _
                                                    & "FROM (tbl_UnitTypes " _
                                                    & "         INNER JOIN tbl_UnitEntry ON tbl_UnitTypes.UnitTypes_ID = tbl_UnitEntry.UnitEntry_UnitTypes_ID) " _
                                                    & "         INNER JOIN (tbl_PMHeader INNER JOIN tbl_PMEntry ON tbl_PMHeader.PMHeader_ID = tbl_PMEntry.PMEntry_PMHeader_ID) ON tbl_UnitEntry.UnitEntry_PMEntry_ID = tbl_PMEntry.PMEntry_PMHeader_ID " _
                                                    & "WHERE ((tbl_PMHeader.PMHeader_ID) = " & num_PM & " )" _
                                                    & "GROUP BY tbl_UnitTypes.UnitTypes_WeeklyTextBoxUserEntryForm, " _
                                                    & "          tbl_UnitTypes.UnitTypes_CumalativeTextBoxUserEntryForm, " _
                                                    & "          tbl_PMEntry.PMEntry_Week_Ending")

1 个答案:

答案 0 :(得分:0)

您的陈述只是缺少必需的空格字符。

问题在于:

& "WHERE ((tbl_PMHeader.PMHeader_ID) = " & num_PM & " )" _
& "GROUP BY tbl_UnitTypes.UnitTypes_WeeklyTextBoxUserEntryForm, " _

)GROUP没有提到任何内容......解决方案:

& "WHERE ((tbl_PMHeader.PMHeader_ID) = " & num_PM & ") " _
& "GROUP BY tbl_UnitTypes.UnitTypes_WeeklyTextBoxUserEntryForm, " _

假设您没有输入任何字段名拼写错误。我注意到你有一个名为UnitTypes_CumalativeTextBoxUserEntryForm的字段,其中正确的拼写是cumulative,但只要你保持一致就不应该成为问题。