Same code does not work in two forms

G

Guest

I have the same code for enabling nav buttons on two forms, both
identical except for content.

The code is
---------------------------
Private Sub Form_Current()

Me.Previous.Enabled = (Me.CurrentRecord >1)
Me.Next.Enabled = (Me.CurrentRecord < Me.RecordsetClone.RecordCount)

End Sub
---------------------------

The only difference between the two forms is the one that works does not
have a BeforeUpdate event. I have already checked, and disabling the
BeforeUpdate event doesn't make any difference.

However, if you select Last or First Record, then the Previous / Next works.

Any help would be appreciated.



Paul.
 
F

fredg

I have the same code for enabling nav buttons on two forms, both
identical except for content.

The code is
---------------------------
Private Sub Form_Current()

Me.Previous.Enabled = (Me.CurrentRecord >1)
Me.Next.Enabled = (Me.CurrentRecord < Me.RecordsetClone.RecordCount)

End Sub
---------------------------

The only difference between the two forms is the one that works does not
have a BeforeUpdate event. I have already checked, and disabling the
BeforeUpdate event doesn't make any difference.

However, if you select Last or First Record, then the Previous / Next works.

Any help would be appreciated.

Paul.

Does this combination work for you in the current event?
Me!Previous.Enabled = Not Me.CurrentRecord = 1
Me!Next.Enabled = Me.CurrentRecord = 1 Or Me.CurrentRecord <
Me.Recordset.RecordCount
 
P

Paul

In some circumstances RecordCount returns -1 unless you have first moved to
the end of the recordset (this is a performance consideration - it takes a
while to move to the end of the recordset if the recordset is large/complex
so Access does not do it automatically - the -1 is supposed to represent
'unknown' because Access does not know how many records there are yet).

Before your second line of code, add the line:

Me.RecordsetClone.MoveLast

This will force the RecordCount property to become properly populated and
return the correct value when called.
 

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