循环遍历 MS Access 中所有记录的代码
我需要一个代码来循环遍历表中的所有记录,以便提取一些数据。除此之外,是否还可以循环过滤记录并再次提取数据?谢谢!
I need a code to loop through all the records in a table so I can extract some data. In addition to this, is it also possible to loop through filtered records and, again, extract data? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该能够使用相当标准的 DAO 记录集循环来完成此操作。您可以在以下链接中查看一些示例:
http://msdn.microsoft.com/en -us/library/bb243789%28v=office.12%29.aspx
http://www.granite.ab.ca/access/email/recordsetloop.htm
我自己的标准循环看起来像这样:
You should be able to do this with a pretty standard DAO recordset loop. You can see some examples at the following links:
http://msdn.microsoft.com/en-us/library/bb243789%28v=office.12%29.aspx
http://www.granite.ab.ca/access/email/recordsetloop.htm
My own standard loop looks something like this:
在“引用”中,导入 DAO 3.6 对象引用。
您可以通过不同的方式交互数据对象,如查询和过滤表:
通过查询:
您还应该查找记录集对象的“Filter”属性,以仅过滤所需的记录,然后以相同的方式与它们交互(请参阅 VB6 帮助) MS-Access 代码窗口),或者创建一个“QueryDef”对象来运行查询并将其用作记录集(有点棘手)。告诉我你是否想要另一种方法。
我希望我有所帮助。
In "References", import DAO 3.6 object reference.
You can interate data objects like queries and filtered tables in different ways:
Trhough query:
You should also look for "Filter" property of the recordset object to filter only the desired records and then interact with them in the same way (see VB6 Help in MS-Access code window), or create a "QueryDef" object to run a query and use it as a recordset too (a little bit more tricky). Tell me if you want another aproach.
I hope I've helped.
找到了一个很好的代码,其中带有解释每个语句的注释。
代码位于 - accessallinone
循环数据时,记录集有两个重要属性:EOF (文件结尾)和 BOF(文件开头)。记录集就像表格一样,当您循环浏览一个记录集时,实际上是按顺序从一个记录移动到另一个记录。当您移动记录时,EOF 属性设置为 false,但在您尝试越过最后一条记录后,EOF 属性变为 true。对于 BOF 属性,这同样适用。
这些属性让我们知道何时达到了记录集的限制。
Found a good code with comments explaining each statement.
Code found at - accessallinone
Recordsets have two important properties when looping through data, EOF (End-Of-File) and BOF (Beginning-Of-File). Recordsets are like tables and when you loop through one, you are literally moving from record to record in sequence. As you move through the records the EOF property is set to false but after you try and go past the last record, the EOF property becomes true. This works the same in reverse for the BOF property.
These properties let us know when we have reached the limits of a recordset.