How to execute a query in ms-access in VBA code?

前端 未结 2 1738
傲寒
傲寒 2020-12-03 03:54

How can I execute a query to return records in an ms-access database using VBA code?

相关标签:
2条回答
  • 2020-12-03 04:34

    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
    
    0 讨论(0)
  • 2020-12-03 04:35

    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
    
    0 讨论(0)
提交回复
热议问题