我有一个表格的事件程序到Execute
一系列
附加查询语句以创建新的相关记录。我得到了一个"编译错误:预期案例"代码的SELECT Inquiries.InquiryID
为红色。确切的代码粘贴在下面。
Private Sub Form_AfterInsert()
Dim db As DAO.Database
Dim strSQL As String
Set db = DBEngine(0)(0)
strSQL = "INSERT INTO PreCallQuestionaireResidential ( InquiryID )"
SELECT Inquiries.InquiryID
FROM Inquiries
db.Execute strSQL
Set db = Nothing
End Sub
答案 0 :(得分:1)
当Access看到SELECT
未加引号时,它希望它成为Select Case
代码块的一部分。
您希望SELECT
字符串中包含strSQL
...
strSQL = "INSERT INTO PreCallQuestionaireResidential ( InquiryID )" & vbCrLf & _
"SELECT Inquiries.InquiryID FROM Inquiries"
Debug.Print strSQL '<- view this in Immediate window; Ctrl+g will take you there