ACCESS VBA INSERT INTO 出现问题

Trouble with ACCESS VBA INSERT INTO

我在插入这个 INSERT INTO 时遇到错误,我似乎无法弄清楚。代码遍历 Dao 记录集以仅将某些记录附加到 table.

    Dim maxDate As Variant

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sqlinsert As String

maxDate = DMax("[Eff Date]", "400_CF_BREAK_LOG")
Set db = CurrentDb


Set rs = db.OpenRecordset("860_APPEND_DIFFERENCES")
If Not rs.BOF Then
    'populate the table
    rs.MoveFirst
    Do
        If (rs![Eff Date] > maxDate Or IsNull(maxDate)) Then
            sqlinsert = "INSERT INTO 400_CF_BREAK_LOG (Eff Date, PrimarySecurity ID Number, CUSIP(Aladdin ID), IsrName, Asset Type, Metlife Port Code, Business Unit, Principal Difference, Total PAM Principal, Total Aladdin Principal,Income Difference, Total PAM Interest,Total Aladdin Interest,Total CF Difference,Total PAM CF,PAM Coupon)" & _
            " VALUES ('" & rs("Eff Date") & "', '" & rs("PrimarySecurity ID Number") & "', '" & rs("CUSIP(Aladdin ID)") & "', '" & rs("IsrName") & "', '" & rs("Asset Type") & "', '" & rs("Metlife Port Code") & "', '" & rs("Business Unit") & "', '" & rs("Principal Difference") & "',  '" & rs("Total PAM Principal") & "',  '" & rs("Total Aladdin Principal") & "','" & rs("Income Difference") & "', '" & rs("Total PAM Interest") & "', '" & rs("Total Aladdin Interest") & "', '" & rs("Total CF Difference") & "', '" & rs("Total PAM CF") & "', '" & rs("PAM Coupon") & "') "
            DoCmd.RunSQL (sqlinsert)
        End If
        rs.MoveNext
    Loop Until rs.EOF
End If

我一直在 INSERT INTO 语句中收到语法错误,但我已经检查了几次。

编辑 - 解释。标签

带空格或punctuation/special个字符的名称(唯一例外是下划线)需要用[]括起来。最好在命名约定中避免这些。但是,对带引号的记录集字段的引用应该可以在不包含在 [ ] 中的情况下使用。需要 [ ] 的替代语法是:rs![Eff Date].

sqlinsert = "INSERT INTO 400_CF_BREAK_LOG ([Eff Date], [PrimarySecurity ID Number],  
[CUSIP(Aladdin ID)], IsrName, [Asset Type], [Metlife Port Code], [Business Unit],  
[Principal Difference], [Total PAM Principal], [Total Aladdin Principal],  
[Income Difference], [Total PAM Interest], [Total Aladdin Interest], [Total CF Difference],  
[Total PAM CF], [PAM Coupon])" & _  
" VALUES ('" & rs("Eff Date") & "', '" & rs("PrimarySecurity ID Number") & "', '" & 
rs("CUSIP(Aladdin ID)") & "', '" & rs("IsrName") & "', '" & rs("Asset Type") & "', '" & 
rs("Metlife Port Code") & "', '" & rs("Business Unit") & "', '" & rs("Principal Difference") & "',  '" & 
rs("Total PAM Principal") & "',  '" & rs("Total Aladdin Principal") & "','" & 
rs("Income Difference") & "', '" & rs("Total PAM Interest") & "', '" & 
rs("Total Aladdin Interest") & "', '" & rs("Total CF Difference") & "', '" & rs("Total PAM CF") & "', '" & 
rs("PAM Coupon") & "') "