ms-access - 如何解决此代码中的运行时错误?
问题描述
我收到运行时错误 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
该Execute
方法将运行操作查询或执行提供的 SQL 语句,它不会评估另一个数据库中的 VBA 代码。
推荐阅读
- authentication - 如何将基本身份验证添加到 Mapbox 中 WMS 源的标头
- wiremock - Wiremock 没有模板化请求路径段
- macos - OSX:Chrome 无法连接到 .localhost-domains。拒绝连接
- python - 如何在 python 中通过请求获取代理?
- flutter - 意外的空值颤振
- python-3.x - python中按模块搜索路径顺序输入路径是什么意思?
- angular - Angular Material DateRangePicker 更改左上角日期格式
- php - 在 RouteCollection 中使用实体管理器
- css - mPDF -和操纵失败
- gherkin - 黄瓜 - 重复步骤