M
Matt Williamson
What am I missing here? I'm trying to determine if the recordset returned
from a dynamic query is empty, but it's always returning empty even when it
contains records. Is there a better way to check for an empty recordset?
'decs snipped
Set MyDB = CurrentDb()
strSQLPorts = "Select " 'Gets list of portcodes to use in next query
MyDB.QueryDefs.Delete ("Portlist")
Set qdf = MyDB.CreateQueryDef("Portlist", strSQLPorts)
Set rstPorts = qdf.OpenRecordset(dbOpenSnapshot)
With rstPorts
Do While Not .EOF
strSQL = "SELECT ..."
strWhere = 'Where clause
strSQL = strSQL & strWhere
' Debug.Print strSQL
MyDB.QueryDefs.Delete ("DynPerfCalcs")
Set qdf = MyDB.CreateQueryDef("DynPerfCalcs", strSQL)
Set rstData = qdf.OpenRecordset(dbOpenSnapshot)
If Not rstData.BOF And rstData.EOF Then
DoCmd.OutputTo acOutputReport, "YearEndPerfDyn", acFormatRTF,
"C:\temp\" & .Fields("portfoliocode") & ".doc"
Else
Debug.Print "No records returned for portcode: " &
..Fields("portfoliocode")
End If
strSQL = ""
.MoveNext
Loop
End With
TIA
Matt
from a dynamic query is empty, but it's always returning empty even when it
contains records. Is there a better way to check for an empty recordset?
'decs snipped
Set MyDB = CurrentDb()
strSQLPorts = "Select " 'Gets list of portcodes to use in next query
MyDB.QueryDefs.Delete ("Portlist")
Set qdf = MyDB.CreateQueryDef("Portlist", strSQLPorts)
Set rstPorts = qdf.OpenRecordset(dbOpenSnapshot)
With rstPorts
Do While Not .EOF
strSQL = "SELECT ..."
strWhere = 'Where clause
strSQL = strSQL & strWhere
' Debug.Print strSQL
MyDB.QueryDefs.Delete ("DynPerfCalcs")
Set qdf = MyDB.CreateQueryDef("DynPerfCalcs", strSQL)
Set rstData = qdf.OpenRecordset(dbOpenSnapshot)
If Not rstData.BOF And rstData.EOF Then
DoCmd.OutputTo acOutputReport, "YearEndPerfDyn", acFormatRTF,
"C:\temp\" & .Fields("portfoliocode") & ".doc"
Else
Debug.Print "No records returned for portcode: " &
..Fields("portfoliocode")
End If
strSQL = ""
.MoveNext
Loop
End With
TIA
Matt