Access 2007 Split Form

J

JamesJ

Hi. Using the following code to emulate the record count
on the navigation buttons.

Dim RecClone As Recordset
Dim intCount As Integer
Dim intPosition As Integer

Set RecClone = Me.RecordsetClone()

If IsNull(Me.DvdMovieID) Then

Else

RecClone.MoveLast
intCount = RecClone.RecordCount
RecClone.Bookmark = Me.Bookmark
intPosition = RecClone.AbsolutePosition + 1
lblCount.Caption = intPosition & " of " & intCount

End If

RecClone.Close

When I click on the "Record Selector" on the Datasheet nothing
happens. The records indicators on the forms Navigation Buttons
seem to work but I can't get the label to display the record number
when selecting a record.

Before you ask, I don't particularly like the form's Navigation Buttons.\
Their too small and I'd like to create my own Nav Bar.
 
A

Allen Browne

There are lots of issues with your approach:

1. In what event are you running this code?
You need to run it in the Current event of the form to get the update.
From memory, the display won't update until this event completes.

2. The code will fail if there is no record, or if the form is at a new
record where there is no record.

3. Due to a bug in Access, it will also return the wrong answer if you are
at the new record and have started entering a new record: Access wrongly
reports the bookmark of the most recently visited record as the one for the
new record.

4. Don't close RecClone. You didn't open it. Access will silently recover
without any bad effects that I know of in this case, but there are bad
effects in other cases. One example here:
http://allenbrowne.com/ser-37.html

5. Why not use the CurrentRecord of the form directly, i.e.:
Me.CurrentRecord

6. The record number and count in the nav buttons adjusts for the case where
you are at the new record. You will need to handle this also.

7. If you use command buttons on your form, you will not be able to hold the
button down to continue moving records. Setting the button's AutoRepeat
property does not work. (Placing the buttons in a subform does, but that's a
whole other story.)

8. The code is inefficient. It delays the form loading (all records must
load before the first Current event can complete), and continually resets
and moves the clone set's pointer with every record you visit. This will not
be a good idea in a multi-user database, or where the volume of network
traffic matters.

Are the built-in nav buttons beginning to look good yet? :)
 
J

JamesJ

OnCurrrent of the form. I wasn't planning on using nav buttons to
navigate I said nothing to that effect.I simply want a label
to display the current record and the number of records. If I was
going to use Nav buttons to navigate I wouldn't be concerned with
the fact record number and number of records are not changing
when I click on a record selector.
This code works fine when I'm using it on a form from Access 2003.
This is where I got it from.
And, no the nav buttons still don't look good to me. They give you
a new record button but no delete record button....

James
 
A

Allen Browne

Thank you for your answer to the first and last questions.

You may find some more help in 2 ~ 6.
 

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