带有recordset.open的无效SQL语句

发布于 2025-02-03 09:46:08 字数 2229 浏览 4 评论 0原文

我遇到一个运行时错误:

-2147217900在我的代码的这一行上“无效的SQL语句”:

Call objRecordset.Open("frmTotalInventory", , , adLockBatchOptimistic)

我在另一个MS Access Project中使用了相同的代码,唯一的区别是它引用的形式是“ FrmtotAtalInventory”。

我检查了两个访问项目之间的库参考匹配,我完全不确定为什么我会收到SQL语句错误。另一个访问项目的“库存”为recordset.open,如果有帮助。完整的代码下面列出。如果有人有任何想法,请告诉我。 FRM是一个保留的词吗?

Option Compare Database

Private Sub Command1_Click()
On Error GoTo ErrorHandlerCall

GoTo ProgramStart 'Skip over error handling until needed

                                            '******************
ErrorHandlerCall:                           '**ERROR HANDLING**
Call Error.ErrorHandler(ByVal workbook)     '******************
                                                

ProgramStart:

'Open file dialog opens and returns the selected filepath from OpenFile module
Call OpenFileDialog(FilePath)
    
'Reset progress bar and progress label to 0
'so each time you import the values will reset
PB1 = 0
ProgressPercent.Caption = 0 & "%"
   
Dim ExcelApp As Excel.Application
Set ExcelApp = CreateObject("Excel.Application")
Set workbook = ExcelApp.Workbooks.Open(FileName:=(FilePath))
    
'This is needed to add records with VBA
Dim objRecordset As ADODB.Recordset
Set objRecordset = New ADODB.Recordset
objRecordset.ActiveConnection = CurrentProject.Connection

Call objRecordset.Open("frmTotalInventory", , , adLockBatchOptimistic)
    
'Loop runs within the LastRowFinder module to determine
'the last row used in the formatted workbook

Call GetLastRow(ByVal workbook, LastRowUsed)
    
'Math - This has to be after the "Call GetLastRow" in order for it to return
'the LastRowUsed variable that is used for calculating progress
Dim PbIncrement As Variant
PbIncrement = 1 / LastRowUsed
PbIncrement = Round(PbIncrement, 6) * 100
    
Call AddRecordsLoop(ByVal objRecordset, ByVal workbook, LastRowUsed, PbIncrement)
    
'Ensures progress bar is at 100% after adding all records
PB1 = 100
ProgressPercent.Caption = Round(PB1, 0) & "%"

'Close Excel Process
If Not (ExcelApp Is Nothing) Then ExcelApp.Quit


End Sub

I am getting a runtime error:

-2147217900 "Invalid SQL statement" on this line of my code:

Call objRecordset.Open("frmTotalInventory", , , adLockBatchOptimistic)

I have this same code working in another MS Access project and the only difference is the form that it is referencing which is "frmTotalInventory".

I checked and the library references match between the two Access projects and I am not sure at all why I would be getting an SQL statement error. The other Access project has "InventoryForm" as the form referenced for the Recordset.Open if that helps. Full code listed below. If anyone has any ideas please let me know. Is frm a reserved word?

Option Compare Database

Private Sub Command1_Click()
On Error GoTo ErrorHandlerCall

GoTo ProgramStart 'Skip over error handling until needed

                                            '******************
ErrorHandlerCall:                           '**ERROR HANDLING**
Call Error.ErrorHandler(ByVal workbook)     '******************
                                                

ProgramStart:

'Open file dialog opens and returns the selected filepath from OpenFile module
Call OpenFileDialog(FilePath)
    
'Reset progress bar and progress label to 0
'so each time you import the values will reset
PB1 = 0
ProgressPercent.Caption = 0 & "%"
   
Dim ExcelApp As Excel.Application
Set ExcelApp = CreateObject("Excel.Application")
Set workbook = ExcelApp.Workbooks.Open(FileName:=(FilePath))
    
'This is needed to add records with VBA
Dim objRecordset As ADODB.Recordset
Set objRecordset = New ADODB.Recordset
objRecordset.ActiveConnection = CurrentProject.Connection

Call objRecordset.Open("frmTotalInventory", , , adLockBatchOptimistic)
    
'Loop runs within the LastRowFinder module to determine
'the last row used in the formatted workbook

Call GetLastRow(ByVal workbook, LastRowUsed)
    
'Math - This has to be after the "Call GetLastRow" in order for it to return
'the LastRowUsed variable that is used for calculating progress
Dim PbIncrement As Variant
PbIncrement = 1 / LastRowUsed
PbIncrement = Round(PbIncrement, 6) * 100
    
Call AddRecordsLoop(ByVal objRecordset, ByVal workbook, LastRowUsed, PbIncrement)
    
'Ensures progress bar is at 100% after adding all records
PB1 = 100
ProgressPercent.Caption = Round(PB1, 0) & "%"

'Close Excel Process
If Not (ExcelApp Is Nothing) Then ExcelApp.Quit


End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们的影子 2025-02-10 09:46:08

好吧,我感觉不太愚蠢。在整个过程中,我没有意识到我是在提到表格而不是表格。.名字让我在两个项目之间感到困惑,因为我正在从事的项目不是由我创建的。感谢您让我意识到某人实际上是多么愚蠢。

解决方案是将“ frmtotalinventory”更改为“ tblinventoryList”,这是实际 table i试图参考的名称。

Well I could not feel more stupid. This entire time I did not realize I was referencing the form instead of a table.. the names had me confused between my two projects as the one I am working on was not created by me. Thank you for making me realize how dumb someone can actually be.

The solution was to change "frmTotalInventory" to "tblInventoryList" which is the name of the actual TABLE I was trying to reference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文