Click to See Complete Forum and Search --> : How to judge whether a Recordset are Null or not


stonezhang
June 13th, 2001, 11:39 AM
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 stone.zhang@one2one.co.uk

tks a lot

Clearcode
June 13th, 2001, 01:00 PM
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

Iouri
June 13th, 2001, 01:24 PM
If Not IsNull(rs.Field(0)) then Debug.print "Good"


Iouri Boutchkine
iouri@hotsheet.com

d.paulson
June 13th, 2001, 01:35 PM
If not rs.EOF and rs.BOF then debug.print "Good"

David Paulson

Mikael99
July 18th, 2001, 08:39 AM
Its enough to just:
if rs.eof then
do nothing
else
Do until rs.eof
bla
loop
end if