Initial Load of Form display incorrect record number.

D

Dirk

I'm working with Access 2002 and I'm able to show a count of records
using a label on a form without using the Access navigational buttons.
I have created my own custom navigational command buttons. The label
works fine except when the form loads for the first time. The label
displays that I have 50 records when I really have over 400. Once I
start navigating using custom buttons, the record count appear
correctly and remains correct during other operations (adding new
record, deleting record etc.). It's only when the form loads for the
first time. This is the code I've used in the Form_Current event
handler.

Dim rs As Recordset
Dim rc As Long
Set rs = Me.RecordSetClone
With rs
.MoveFirst
.MoveLast
rc = .RecordCount
End With
Me.label46 = "Record " & Me.CurrentRecord & " of " & rc

Do I need to add code to the Form_Load Event. Any help would be
greatly appreciated.

Dirk
 
P

Peter R. Fletcher

This is normal - RecordCount takes a little while to be correct - in
effect, Access actually counts the records in the Form's RecordSet and
does not treat it as a very high priority activity. If you want it to
be accurate from the word go, you need to do something like putting a
..FindFirst followed by a .FindLast in the Form's OnLoad Event, so that
RecordCount is set up immediately.

I'm working with Access 2002 and I'm able to show a count of records
using a label on a form without using the Access navigational buttons.
I have created my own custom navigational command buttons. The label
works fine except when the form loads for the first time. The label
displays that I have 50 records when I really have over 400. Once I
start navigating using custom buttons, the record count appear
correctly and remains correct during other operations (adding new
record, deleting record etc.). It's only when the form loads for the
first time. This is the code I've used in the Form_Current event
handler.

Dim rs As Recordset
Dim rc As Long
Set rs = Me.RecordSetClone
With rs
.MoveFirst
.MoveLast
rc = .RecordCount
End With
Me.label46 = "Record " & Me.CurrentRecord & " of " & rc

Do I need to add code to the Form_Load Event. Any help would be
greatly appreciated.

Dirk


Please respond to the Newsgroup, so that others may benefit from the exchange.
Peter R. Fletcher
 
D

Dirk

Thank's everyone for your great responses. I've tried all that has
been recommended, but still have the same results. Thinking that
something is incorrect with my form, I've developed a new form using
the same table that the other form uses. However this time I used the
MS Access default navigational buttons. When the form loads, the
record count is 50 and then a few seconds later it adjusts to the
correct record amount. I just need to get my labels to refresh much
like the default navigational buttons. I've tried Me.Refresh, using a
textbox instead of a label with no success. The code in both event
handlers is a follows:

Private Sub Form_Current()
Dim rst As Recordset
Dim lngCount As Long
Set rst = Me.RecordsetClone
With rst
If rst.RecordCount > 0 Then
.MoveFirst
.MoveLast
lngCount = .RecordCount

End If
End With
Me.Label46.Caption = "Record " & Me.CurrentRecord & " of " &
lngCount

End Sub

Private Sub Form_Load()

Dim rs As Recordset
Dim lngCount2 As Long
Set rs = Me.RecordsetClone
With rs
If .RecordCount > 0 Then
.MoveFirst
.MoveLast
lngCount2 = .RecordCount
End If
End With

'Me.Label46.Caption = "Record " & Me.CurrentRecord & " of " &
lngCount
Me.Label44.Caption = lngCount2 & " Total Records"
Me.Refresh
End Sub


Any suggestions or comments would be greatly appreciated.

Thanks
 

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