I am attempting to iterate a query as a DAO.Recordset
, my issue is that my recordset never prints anything. If I look at my table, and my query both of them have the data that I am after, but the VBA is not producing the data that I expect. Below is synatx - why will this not write my data?
Option Compare Database
Sub Test()
Dim query1 As String, rs1 As DAO.Recordset
Dim qryDef As QueryDef, strSQL As String
query1 = "qryPullData"
strSQL = "SELECT fl1 As [Field With Spaces One],fl2 As [Field With Spaces Two], " & _
"fl3 As [Field WIth Spaces Three], fl4 As [Field With Spaces Four] " & _
"FROM smallsubset ORDER BY fl1 ASC;"
Set qryDef = CurrentDb.CreateQueryDef(query1, strSQL)
Set rs1 = CurrentDb.OpenRecordset(query1)
If Not rs1.EOF Then
While Not rs1.EOF
Debug.Print rs1("Field With Spaces One")
Debug.Print rs1("Field With Spaces Two")
Debug.Print rs1("Field With Spaces Three")
Debug.Print rs1("Field With Spaces Four")
Debug.Print rs1("[Field With Spaces One]")
Debug.Print rs1("[Field With Spaces Two]")
Debug.Print rs1("[Field With Spaces Three]")
Debug.Print rs1("[Field With Spaces Four]")
Wend
rs1.Close
End If
End Sub
Here is the code using several of the suggestions from the above comments:
Here is the CheckQuery sub stolen from here: http://www.access-programmers.co.uk/forums/showthread.php?t=206298
Make sure that you are looking in the immediate window for the Debug.Print results.