gpt4 book ai didi

ms-access - 循环遍历 MS Access 中所有记录的代码

转载 作者:行者123 更新时间:2023-12-02 19:44:23 24 4
gpt4 key购买 nike

我需要一个代码来循环遍历表中的所有记录,以便提取一些数据。除此之外,是否还可以循环过滤记录并再次提取数据?谢谢!

最佳答案

您应该能够使用相当标准的 DAO 记录集循环来完成此操作。您可以在以下链接中查看一些示例:
http://msdn.microsoft.com/en-us/library/bb243789%28v=office.12%29.aspx
http://www.granite.ab.ca/access/email/recordsetloop.htm

我自己的标准循环看起来像这样:

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT * FROM Contacts")

'Check to see if the recordset actually contains rows
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst 'Unnecessary in this case, but still a good habit
Do Until rs.EOF = True
'Perform an edit
rs.Edit
rs!VendorYN = True
rs("VendorYN") = True 'The other way to refer to a field
rs.Update

'Save contact name into a variable
sContactName = rs!FirstName & " " & rs!LastName

'Move to the next record. Don't ever forget to do this.
rs.MoveNext
Loop
Else
MsgBox "There are no records in the recordset."
End If

MsgBox "Finished looping through records."

rs.Close 'Close the recordset
Set rs = Nothing 'Clean up

关于ms-access - 循环遍历 MS Access 中所有记录的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5864160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com