Form Displaying Wrong Number of Records

J

JamesJ

Access 2007

I have the following code in the On Current of my form

Dim intNewrec As Integer

intNewrec = IsNull(Me.DvdMovieID)

If intNewrec Then

lblCount.Caption = "***New Record***"

Else

lblCount.Caption = RecordsetClone.RecordCount & " Items"

End If

When the form initially opens lblCount displays "1 Items" until I select a
record then
the correct number of records are shown. The same code is in othewr forms
with no problems.

Any ideas?

Thanks
James
 
M

Marshall Barton

JamesJ said:
Access 2007

I have the following code in the On Current of my form

Dim intNewrec As Integer

intNewrec = IsNull(Me.DvdMovieID)

If intNewrec Then

lblCount.Caption = "***New Record***"

Else

lblCount.Caption = RecordsetClone.RecordCount & " Items"

End If

When the form initially opens lblCount displays "1 Items" until I select a
record then
the correct number of records are shown. The same code is in othewr forms
with no problems.


RecordSount is only the number of records that have been
accessed so far. To get the total:

With Me.RecordsetClone
.MoveLast
lblCount.Caption = .RecordCount & " Items"
End If
 
J

JamesJ

Why do my other forms with the same code (except different ID field) display
the total number of records?

James
 
M

Marshall Barton

For performance reasons, Access only loads enough records to
display the form, the remaing records are loaded as a
separate background task with a lower priority.

Based on that information, how fast a form's records are
loaded depends on how many records are in the form's record
source, how busy Access is doing other things (e.g. painting
the screen, calculating control values, loading combo/list
box records, etc) and how busy Windows is with other
programs (e.g. loading a web page).

Bottom line, unless you do something to force the records to
be loaded (e.g. .MoveLast or scrolling), it's a crap shoot
when RecordCount will return the count of all the records.
(This is documented in VBA Help - RecordCount)
 
J

JamesJ

I get it now. The code you provided works fine.

Thanks,
James

Marshall Barton said:
For performance reasons, Access only loads enough records to
display the form, the remaing records are loaded as a
separate background task with a lower priority.

Based on that information, how fast a form's records are
loaded depends on how many records are in the form's record
source, how busy Access is doing other things (e.g. painting
the screen, calculating control values, loading combo/list
box records, etc) and how busy Windows is with other
programs (e.g. loading a web page).

Bottom line, unless you do something to force the records to
be loaded (e.g. .MoveLast or scrolling), it's a crap shoot
when RecordCount will return the count of all the records.
(This is documented in VBA Help - RecordCount)
--
Marsh
MVP [MS Access]

Why do my other forms with the same code (except different ID field)
display
the total number of records?


"Marshall Barton" wrote
 

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