2016-07-24 184 views
0

我得到在MS Access錯誤,而基於組合框MS ACCESS - 錯誤運行SQL 3141中VBA

The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect. 

這裏我的代碼

Private Sub Text4_AfterUpdate() 
If (Me.Text4.Value = "(ALL)") Then 
    filterORIGIN_COD = "SELECT SUMMARY.DEST_CITY, SUMMARY.DESTINATION, Count(SUMMARY.CNOTE_NO) AS CountOfCNOTE_NO1" & _ 
       "FROM SUMMARY" & _ 
       "WHERE (((SUMMARY.ORIGIN_CODE) Like " & "'" * "'" & ")))" & _ 
       "GROUP BY SUMMARY.DEST_CITY, SUMMARY.DESTINATION, SUMMARY.TGL_DATA, SUMMARY.ORIGIN_CODE, SUMMARY.ORIGIN, SUMMARY.DEST_CODE;" 


Else 
    filterORIGIN_COD = "SELECT SUMMARY.DEST_CITY, SUMMARY.DESTINATION, Count(SUMMARY.CNOTE_NO) AS CountOfCNOTE_NO1" & _ 
       "FROM SUMMARY" & _ 
       "WHERE (((SUMMARY.ORIGIN_CODE)=" & """Me![Text4]""" & ")))" & _ 
       "GROUP BY SUMMARY.DEST_CITY, SUMMARY.DESTINATION, SUMMARY.TGL_DATA, SUMMARY.ORIGIN_CODE, SUMMARY.ORIGIN, SUMMARY.DEST_CODE;" 

End If 
Me![OUTBOUND_DETAIL].Form.RecordSource = filterORIGIN_COD 
Me![OUTBOUND_DETAIL].Requery 


End Sub 

附加試圖改變窗體記錄源 實際上我試圖過濾子表單(查詢記錄源),有人能告訴我更好的方法來做到這一點嗎? :)

+1

結果字符串之前有沒有空間單詞「FROM」,例如「... CountOfCNOTE_NO1FROM SUMMARY ...」 –

回答

0

如果試圖在一個觸發事件篩選子窗體,只需使用DoCmd.ApplyFilterDoCmd.SetFilter(用於訪問2010+)方法,其也可在宏:

Private Sub Text4_AfterUpdate() 
    DoCmd.ApplyFilter , "[SUMMARY.ORIGIN_CODE]='" & Me![Text4] & "'" 
End Sub