首页 > 解决方案 > 如何解决此代码中的运行时错误?

问题描述

我收到运行时错误 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

标签: ms-accessvba

解决方案


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

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

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


推荐阅读