Ms access 如何解决此代码中的运行时错误?

Ms access 如何解决此代码中的运行时错误?,ms-access,vba,Ms Access,Vba,我得到一个运行时错误3075 我已经检查了所有的括号和引号,看起来一切正常,但仍然没有运行 '现在检查数据库,查看是否存在有关月份和年份的现有记录 txtSQL = "SELECT Count([Rec_ID]) AS CountID FROM [dbo_NBD_EMEA_NBD_Source_Download] Where [Ledger_Year] = " & CurYear & " AND [Ledger_Month] = " & CurMonth & "

我得到一个运行时错误3075

我已经检查了所有的括号和引号,看起来一切正常,但仍然没有运行

'现在检查数据库,查看是否存在有关月份和年份的现有记录

txtSQL = "SELECT Count([Rec_ID]) AS CountID FROM [dbo_NBD_EMEA_NBD_Source_Download] Where [Ledger_Year] = " & CurYear & " AND [Ledger_Month] = " & CurMonth & " AND ([Region_Cd] = 'EMEA' OR [Region_Cd] = 'APAC' OR [Region_Cd] = 'INDA');"
Set dbs = CurrentDb
Set Rs = dbs.OpenRecordset(txtSQL, dbOpenSnapshot)
NumRecs = Rs("CountID")
Rs.Close
If NumRecs > 0 Then
    Prompt1 = "WARNING... There are " & NumRecs & " Records already in the database for Year " & CurYear & " Month " & CurMonth & Chr(10) & " Do you want to ERASE the existing records and REPLACE them with the NEW RECORDS in your IMPORT FILE " & Chr(10) & Selected_File & "?"
    Response1 = MsgBox(Prompt1, Style2, "DELETE EXISTING RECORDS IN DATABASE?")
    If Response1 = vbOK Then 'Continue with Delete of existing Records and Import of new
        Prompt2 = "Confirm... Existing Records will be deleted and replaced with your new file"
        Response2 = MsgBox(Prompt2, Style2, "Confirm Deletions")
            If Response2 = vbOK Then
            'Run Stored Procedure to delete the records
                Me.ProcessStatus.Caption = "Deleting existing records"
                Set db = DBEngine.Workspaces(0).OpenDatabase("", False, False, Connect_String)
                db.Execute "XPROC1_NBD_EMEA_Source_Download_Delete " & CurYear & " , " & CurMonth, dbSQLPassThrough
                Set db = Nothing
            Else
                If Response2 = vbCancel Then 'If no confirmation of delete then cancel
                    Me.ProcessStatus.Caption = "Import Canceled"
                    Exit Sub
                End If
            End If
    Else
        If Response1 = vbCancel Then ' Cancel import
            Me.ProcessStatus.Caption = "Import Canceled"
            Exit Sub
        End If
    End If

End If

此行看起来不是有效的SQL:

db.Execute "XPROC1_NBD_EMEA_Source_Download_Delete " & CurYear & " , " & CurMonth, dbSQLPassThrough

该方法将运行操作查询或执行提供的SQL语句,它不会计算另一个数据库中的VBA代码。

它是MS Access中使用的VB代码。怎么了?我是Access/SQL新手。这不是
Execute
方法的工作原理-我已经更新了我的答案。我该如何解决它?它抛出了语法错误。查询表达式“[Ledge_Year]”中的运行时错误“3075”语法错误(逗号)=019,3,3/19/2019,3/20/2019,EMEA,Q896,匈牙利,AR-in,ARIN-1000,S3WWERR000,