2016-12-14 63 views

回答

3

這爲我工作與返回整數查詢:

Public Sub runQuery(ByVal query As String) 

    Dim DB As DAO.Database: Set DB = CurrentDb() 
    Dim rst As DAO.Recordset: Set rst = DB.OpenRecordset(query) 

    Do While Not rst.EOF 
     Dim rowStr As String: rowStr = "" 
     Dim fld As Field 
     For Each fld In rst.Fields 
      rowStr = rowStr & fld & " " 
     Next fld 

     Debug.Print (rowStr) 

     rst.MoveNext 

    Loop 

End Sub 

然後從即時窗口調用它:

runQuery "SELECT Foo, Bar FROM MyTable WHERE Foo < 42"