Connecting Tech Pros Worldwide Forums | Help | Site Map

how to avoid either eof or bof error

chandru8's Avatar
Familiar Sight
 
Join Date: Sep 2007
Posts: 145
#1: Feb 28 '08
ho to all
iam retrieving data from the access table when there is no data it saying either EOF or BoF true . how to avoid this.
If IsNull(rs.Fields(0)) = True Then

B = 1
Else
B = rs.Fields(0) + 1
End If

if there is no data b = 1 otherwise i need to increment that value B by 1
thanks to all

Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#2: Feb 28 '08

re: how to avoid either eof or bof error


You could try checking .RecordCount first, before using the fields.
chandru8's Avatar
Familiar Sight
 
Join Date: Sep 2007
Posts: 145
#3: Feb 28 '08

re: how to avoid either eof or bof error


I Tried Record Count For Many Times But It Doesn't Work For Me .
Rs.recordcount Says -1
Is It Correct
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,508
#4: Feb 28 '08

re: how to avoid either eof or bof error


That means your query is not fetching anything.
chandru8's Avatar
Familiar Sight
 
Join Date: Sep 2007
Posts: 145
#5: Feb 28 '08

re: how to avoid either eof or bof error


data present in the table also recordcount says -1 only and

for this condition

if isnull(rs.fields(0)) = false then

for the above condition if the table contain data or not it returns only false .
debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,508
#6: Feb 28 '08

re: how to avoid either eof or bof error


Try to execute your query in the backend and check if that returns any record or not .
VBWheaties's Avatar
Familiar Sight
 
Join Date: Feb 2008
Posts: 145
#7: Feb 28 '08

re: how to avoid either eof or bof error


The reason recordcount is -1 is because it has not traversed the set of records in the recordset. In other words, it doesn't know yet, how many records are in the recordset.

To get the record count:

Expand|Select|Wrap|Line Numbers
  1.  rs.Movelast
  2.  rs.Movefirst
  3.  Msgbox "There are " rs.RecordCount  & " records"
  4.  
However, this will be ineffective if there is no data.
The best way to check for no data is to check both BOF and EOF as they will be true if no data exists.

Expand|Select|Wrap|Line Numbers
  1. If ((rs.EOF) And (rs.BOF)) Then
  2.    Msgbox "no data"
  3. End If  
  4.  
Newbie
 
Join Date: Feb 2008
Posts: 2
#8: Feb 28 '08

re: how to avoid either eof or bof error


Trying
Expand|Select|Wrap|Line Numbers
  1. if not rs.eof then
  2. '...
  3. else
  4. '...
  5. end if
  6.  
could work also. So if your query does not return any records, the program does not execute what is inside the if part. And would not show any error.
Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#9: Feb 28 '08

re: how to avoid either eof or bof error


Quote:

Originally Posted by VBWheaties

The reason recordcount is -1 is because it has not traversed ...

I just wanted to clarify this a bit, in case chandru8 didn't quite get it. When you first execute the query, the record count will be set to either 0 (no data) or 1 (some data). So you can use it as an indicator of whether something was found, but won't know the actual number of records until you go to the end of the recordset.

Very annoying, but it has been that way for a long time.
chandru8's Avatar
Familiar Sight
 
Join Date: Sep 2007
Posts: 145
#10: Feb 29 '08

re: how to avoid either eof or bof error


thanks to all for your reply
Hi Killer
I tried this one and i fixed the problem by creating a new table . i dont know for that particular table its not working
from the begining the record count is not working for me can you give me some example for that
instead of rs.recordcount i used select count(field name)

thanks.
Member
 
Join Date: Oct 2007
Posts: 41
#11: Feb 29 '08

re: how to avoid either eof or bof error


I think there is no need for moving Records to get Record count. Refresh the recordset & then use RecordCount. I think it will work.
e.g.
rs.refresh
if rs.recordcount=0 then
.
.
Else
.
.
Endif
Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#12: Mar 2 '08

re: how to avoid either eof or bof error


Checking EOF and BOF is probably the better option, anyway.

I don't have any examples handy for recordcount, and don't actually do a lot of work with it. I just remember the problems with the records not being being until they're accessed.
Reply