我试图迭代查询作为DAO.Recordset
,我的问题是,我的记录集从不打印任何东西。如果我看看我的表格,并且我的查询都具有我之后的数据,但VBA不生成我期望的数据。下面是synatx - 为什么这不写我的数据?使用查询作为DAO.Recordset
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
'rsExportExcel'没有声明 - 你有错字吗?你也错过了'MoveNext',除非你想*无限循环 –
@TimWilliams - 是的,我的错误应该是rs1 –
做你的代码进入'While'循环吗? –