试图在论坛上搜索与我类似的线程,但却找不到能引导我朝正确方向发展的任何东西。基本上我有一个表格,其中包含10个地区中每个地区的QA分数,我正在尝试根据月份填充具有特定地区分数的文本框。我试图在vba中为这个表单执行此操作但遇到此运行时错误3131并且我不完全确定我的代码有什么问题对我来说似乎很简单。感谢您提前提供任何帮助或建议。
Private Sub Form_Load()
Dim strSql As String
strSql = "SELECT tblScorecard.[QA_Overall]" & _
"FROM tblScorecard" & _
"WHERE tblScorecard.[Audit Month] = 'Jan'" & _
"AND tblScorecard.[Region] = '1'"
DoCmd.RunSQL strSql
txtReg1 = strSql
End Sub
答案 0 :(得分:1)
你不可能只添加空格吗? tblScorecard。[QA_Overall] FROM as one word?
Private Sub Form_Load()
Dim strSql As String
strSql = "SELECT tblScorecard.[QA_Overall] " & _
"FROM tblScorecard " & _
"WHERE tblScorecard.[Audit Month] = 'Jan'" & _
" AND tblScorecard.[Region] = '1'"
DoCmd.RunSQL strSql
txtReg1 = strSql
End Sub
为了避免错误:2342 A RunSQL:
Private Sub Form_Load()
Dim qdf As QueryDef
strSql = "SELECT tblScorecard.[QA_Overall] " & _
"FROM tblScorecard " & _
"WHERE tblScorecard.[Audit Month] = 'Jan'" & _
" AND tblScorecard.[Region] = '1'"
On Error Resume Next
DoCmd.DeleteObject acQuery, "tempQry"
On Error GoTo 0
Set qdf = CurrentDb.CreateQueryDef("tempQry", strSQL)
DoCmd.OpenQuery ("tempQry")
End Sub
更多信息here。
答案 1 :(得分:1)
当您使用& _
时,您不会在字符串
尝试在字符串末尾添加空格
strSql = "SELECT tblScorecard.[QA_Overall] " & _
"FROM tblScorecard " & _
"WHERE tblScorecard.[Audit Month] = 'Jan' " & _
"AND tblScorecard.[Region] = '1'"