recordset.count behaves strange

H

Hajo

Hi,

When I execute the following code, tmp contains only 1. Actually it should
be 4.
1. Dim tmp As Integer
2. tmp = Me.Recordset.RecordCount

Now, when I set a breakpoint on the 2nd line, tmp will has the correct value
of 4.

Why is that so and what can I do to change that?

Thank you,
Hajo
 
P

Paul Shapiro

You didn't give much detail, but generally the recordcount is only accurate
once you've specifically forced loading all the records. Try something like:

With Me.Recordset
.moveLast
.moveFirst
temp = .RecordCount
End With
 
T

Tom van Stiphout

On Sun, 25 Jan 2009 21:29:36 -0500, "Paul Shapiro"

Since you can't MoveLast on an empty recordset you can also write:

With Me.Recordset
if .RecordCount = 0 then temp = 0
else
.moveLast
.moveFirst
temp = .RecordCount
end if
End With

-Tom.
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top