How to judge whether a Recordset are Null or not
My code is like
Dim conn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sSQL As String
'gSession.GetConn will open connection
Set conn = gSession.GetConn
For i = 1 To 12
strDateTo = frmChart.txtDate(4) & "/" & frmChart.txtDate(3) & "/" & frmChart.txtDate(5)
strDateFrom = frmChart.txtDate(1) & "/" & frmChart.txtDate(0) & "/" & frmChart.txtDate(2)
sSQL = "SELECT * FROM TestResult WHERE TestResult.Handset_Model = '" & strHandsetModel & "'"
sSQL = sSQL & " AND TestResult.Date_Time <= #"
sSQL = sSQL & strDateTo & "#"
sSQL = sSQL & " AND TestResult.Date_Time >= #"
sSQL = sSQL & strDateFrom & "#"
sSQL = sSQL & " AND Code = " & i
sSQL = sSQL & " ORDER BY Date_Time"
rs.Open sSQL, conn, adOpenStatic, adLockReadOnly
' If rs = Null Then Debug.Print "Good"
While Not rs.EOF
Debug.Print rs!Handset_Model, rs!Date_Time, rs!Code
'monthTestFrom = Month(dateTestFrom)
intMonth = (Month(rs!Date_Time) - Month(dateTestFrom)) + 1 + (Year(rs!Date_Time) - Year(dateTestFrom)) * 12
arrStat(intMonth, i + 1) = arrStat(intMonth, i + 1) + 1
rs.MoveNext
Wend
rs.Close
Next i
at first I want to compare rs.RecordCount to zero to decide if the recordset is null but seems does not work. Even there is nothing inside the recordset the RecordCount still = 1
if there is nothing in the rs, i will have prolem with my while loop. would u please tell me how to sort out this problem. email [email protected]
tks a lot
Re: How to judge whether a Recordset are Null or not
Replace
' If rs = null then Debug.print "Good"
with
If (rs.BOF And rs.EOF) then Debug.print "Good"
as this can only be true if RS has no records.
HTH,
D
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Re: How to judge whether a Recordset are Null or not
If Not IsNull(rs.Field(0)) then Debug.print "Good"
Iouri Boutchkine
[email protected]
Re: How to judge whether a Recordset are Null or not
If not rs.EOF and rs.BOF then debug.print "Good"
David Paulson
Re: How to judge whether a Recordset are Null or not
Its enough to just:
if rs.eof then
do nothing
else
Do until rs.eof
bla
loop
end if