Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

empty recordset?

Status
Not open for further replies.

sf123

Programmer
Oct 9, 2002
30
US
I'm trying to loop through a recordset to display the data. Everytime there are no matches I get an error because the recordset is empty. How can I check if the recordset is empty?
I tried rs.recordcount and it seems to always equal -1 before rs.movefirst but it can't do rs.movefirst if there aren't any records.

Here is some of my code:

If (rs.RecordCount = -1) Then
MsgBox ("There were no matches during that time. Please select another timeframe")
frmChoiceWizard.Hide
frmChoiceWizard.Show
Else
rs.MoveFirst
Any ideas? Thanks!

 
I would do domething like:

do while not rs.EOF
....
rs.movenext
loop
 
If rs.BOF And rs.EOF Then
' Recordset is empty. Both EOF and BOF are True
Else
' Recordset has data
End If
 
I tried
if (rs.bof or rs.eof)
msgbox
else
code
end if

but I always got the msgbox because in the beginning before you do rs.movefirst, it will ALWAYS be bof.
 
You have to check for both BOF and EOF... use and AND instead of OR.

When the recordset is empty, both flags will be set to true. When there's data, you are either at BOF, on a record or at EOF, never both. When the recordset is empty, then both flags are set because there's no data in the middle.
 
Your using (or) instead if (And) in your If statement. . .

Like this
If rs.BOF And rs.EOF Then

Not this
If rs.BOF Or rs.EOF Then



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top