vba 获取字符串中的查询结果

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5837846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 13:08:16  来源:igfitidea点击:

Get Query Results in a String

vba

提问by Zack

If I run a query to select three seperate fields from each record. Is it possible to get the results for each returned in three separate strings (one for each field) so that I can cycle through them in vba code?

如果我运行查询以从每条记录中选择三个单独的字段。是否可以在三个单独的字符串(每个字段一个)中获取每个返回的结果,以便我可以在 vba 代码中循环浏览它们?

回答by Bobort

Yes, you can try opening a Recordset and accessing the field values like a collection.

是的,您可以尝试打开 Recordset 并像访问集合一样访问字段值。

Dim d As DAO.Database
Dim r As DAO.Recordset
Set d = CurrentDb()
Set r = d.OpenRecordset("SQL or TableName")
While Not r.EOF
    Debug.Print r!Field1, r!Field2, r!Field3
    r.MoveNext
Wend
r.Close
Set r = Nothing
Set d = Nothing