How can I execute a query to return records in an ms-access database using VBA code?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Take a look at this tutorial for how to use SQL inside VBA:
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
回答2:
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