如何在 VBA 代码中的 ms-access 中执行查询?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4567437/
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
How to execute a query in ms-access in VBA code?
提问by Smith
How can I execute a query to return records in an ms-access database using VBA code?
如何使用 VBA 代码执行查询以返回 ms-access 数据库中的记录?
回答by
How about something like this...
这样的事情怎么样...
Dim rs As RecordSet
Set rs = Currentdb.OpenRecordSet("SELECT PictureLocation, ID FROM MyAccessTable;")
Do While Not rs.EOF
Debug.Print rs("PictureLocation") & " - " & rs("ID")
rs.MoveNext
Loop
回答by zsalzbank
Take a look at this tutorial for how to use SQL inside VBA:
看看这个教程,了解如何在 VBA 中使用 SQL:
http://www.ehow.com/how_7148832_access-vba-query-results.html
http://www.ehow.com/how_7148832_access-vba-query-results.html
For a query that won't return results, use (reference here):
对于不会返回结果的查询,请使用(参考此处):
DoCmd.RunSQL
For one that will, use (reference here):
对于一个将,使用(参考这里):
Dim dBase As Database
dBase.OpenRecordset

