编译错误:预期案例

时间:2016-01-26 18:39:44

标签: ms-access access-vba ms-access-2007

我有一个表格的事件程序到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

1 个答案:

答案 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