ms-access - 传递 RecordCount 属性时 MsgBox 不出现
问题描述
编辑:问题是On Error Resume Next
抑制中的错误OpenRecordset
,将 Variant 设置为 Nothing。OpenRecordset
由于列名拼写错误而失败,并且在默认情况下由作为链接表的代理确定类型时指定类型。
解决方案:注释掉/删除On Error Resume Next
以引发错误。更正列名中的拼写错误。从链接表查询时不要指定类型(将位置留空)(对于来自链接表的查询,类型自动为动态集。
在代码的特定部分中,我试图显示记录集中的记录数(主要用于调试目的)。我偶然发现了我认为是一个独特的错误。代码如下:
specsVariableTempTableName = "specs_variable_" & CStr(Me.OpFormOpRecordID) & "_temp"
specItemsQuery = "SELECT [Item], [Document #], [Item Description], [SubItems], [Attribute], [Spec Characteristics] FROM [tbl_forms] WHERE [Document #] = '" & Me![Form #] & "' AND [Part #] = '" & Me![Part Number] & "';"
Set db_source = CurrentDb
If IsNull(DLookup("Name", "MSysObjects", "Name='" & specsVariableTempTableName & "' And Type In (1,4,6)")) Then
'Check for existing temporary spec table
'Create one if not
MsgBox ("No temporary table " & specsVariableTempTableName)
Set specItemsRecordSet = db_source.OpenRecordset(specItemsQuery, , dbFailOnError).Clone
MsgBox (specItemsRecordSet.RecordCount & " Records")
MsgBox ("What the f***")
If Not (specItemsRecordSet.EOF And specItemsRecordSet.BOF) Then
'If the result set is not empty, go to first entry
specItemsRecordSet.MoveFirst
With specItemsRecordSet
MsgBox (.RecordCount)
End With
Else
MsgBox ("No Specs found for given part number and document number")
End If
db_source.Execute "SELECT [Document #], [Part #], [ParentItem], [SubItem], [Nominal], [LSL], [USL], [UOM] INTO " & specsVariableTempTableName & " FROM [Specs_Variable] WHERE (([Specs_Variable]![Document #] = '" & Me![Form #] & "') AND ([Specs_Variable]![Part #] = '" & Me![Part Number] & "'));", dbFailOnError
End If
有问题的行是 MsgBox(specItemsRecordSet.RecordCount & "Record")。此行之前和之后的 MsgBox 行显示一个 MsgBox,我必须单击 OK 关闭它。但是,这一行没有显示 MsgBox,代码没有暂停,它只是继续到下一行,就好像代码根本不存在一样。
我试图重命名查询中的表,我在调用 .RecordCount 之前尝试过 .MoveLast。甚至 WITH 块中的 MsgBox 也不显示。我希望如果查询没有返回任何结果,我会在尝试在 MsgBox 中显示时得到 0、Null 或错误,但 MsgBox 仍会显示并需要用户操作才能继续。
解决方案
推荐阅读
- axis2 - Axis2 1.7.8 中的参数序列
- sql - sql server 加入多行问题
- wpf - WPF MVVM Stylet,如何在命令绑定中使用 s:Action,而不将 Bootstrapper 导入项目?
- reactjs - 条件渲染以选择显示设置
- javascript - 使用 jwt、node/express 验证令牌时请求返回 404
- python - 使用 Pyodbc 包从 sql 数据库中获取数据
- javascript - Javascript将变量视为字符串
- dax - 在 DAX 度量中计算当前日期减去 6 个月
- sql-server - 如何更新 SQL Server 项目中的数据库函数
- git - 我在 git config 中添加了错误的变量。如何删除它?