简体   繁体   English

Access 2007:Form Recordset.RecordCount 为 0,SQL 应该有记录

[英]Access 2007: Form Recordset.RecordCount is 0 with SQL that should have records

The RecordSource is a simple "SELECT field1, field2, field3 FROM table WHERE field1=value" which is set in the Open even of the form (I make sure to Requery) with the value of the where clause being passed via OpenArgs. RecordSource 是一个简单的“SELECT field1, field2, field3 FROM table WHERE field1=value”,它在表单的 Open even 中设置(我确保重新查询),其中 where 子句的值通过 OpenArgs 传递。 I am able to add/edit records using the bound controls.我可以使用绑定控件添加/编辑记录。

Using Debug.Print on the form's RecordSource (actually via Timer, just to be sure nothing is changing it after the Open event) returns a SQL string which I can then plug in to query design and verify that there are in fact records, yet they fail to populate in the form.在表单的 RecordSource 上使用 Debug.Print(实际上是通过 Timer,只是为了确保在 Open 事件之后没有任何更改)返回一个 SQL 字符串,然后我可以将其插入查询设计并验证是否存在实际记录,但它们无法填充表单。 Debug.Print on the form's Recordset.RecordCount yields 0.窗体的 Recordset.RecordCount 上的 Debug.Print 产生 0。

I am not passing a WHERE clause in my DoCmd.OpenForm statement.我没有在 DoCmd.OpenForm 语句中传递 WHERE 子句。 The form has a blank filter, is not set to filter on load, and does not allow filters.该表单有一个空白过滤器,未设置为在加载时过滤,并且不允许过滤器。 So, I can't imagine that is messing things up.所以,我无法想象这是把事情搞砸了。

What am I missing here?我在这里缺少什么?

Depending on how the recordset is opened, it may not show any records until you move forward in the recordset.根据记录集的打开方式,在您在记录集中向前移动之前,它可能不会显示任何记录。 You can see if this is your problem by typing 'myRecordset.MoveLast' before you do your check on the RecordCount.在检查 RecordCount 之前,您可以通过键入“myRecordset.MoveLast”来查看这是否是您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM