Strange Record Count Problem

G

Guest

Using Access 2000 (9.0.6926 SP3)

I have a basic form used for viewing records. On this form are next and
previous record buttons located at the top of the page. My client wants
these buttons to be enabled/disabled when appropriate. Sounds easy enough
but I'm running into a strange problem.

In the Form_Current event is the code:

If Me.CurrentRecord = Me.RecordsetClone.RecordCount Then
Me.cmdNextRecord.Enabled = False
Else
Me.cmdNextRecord.Enabled = True '**
End If

If I put a break point at '**, the code breaks when the form opens.
However, in break mode, I get the following from the immediate window:

?Me.CurrentRecord = Me.RecordsetClone.RecordCount
True

Is there some sort of timing issue here? The record source is not changing
(to my knowledge) in the OnCurrent event. If I put a break point before the
code, and step through slowly, it seems to work fine. I have a new(er) PC
that shouldn't have any problems with the forms record source query. Any
thoughts, suggestions, comments, or even snide remarks are wanted. Thanks in
advnace.
 
W

Wayne Morgan

Check out the AbsolutePosition property of the form's recordset.

If Me.Recordset.AbsolutePosition = Me.Recordset.RecordCount Then
or
If Me.Recordset.AbsolutePosition + 1 = Me.Recordset.RecordCount Then

In ADO the AbsolutePosition is 1 based, in DAO it is 0 based.
 
M

Marshall Barton

"Christopher Cormier" <Christopher
Using Access 2000 (9.0.6926 SP3)

I have a basic form used for viewing records. On this form are next and
previous record buttons located at the top of the page. My client wants
these buttons to be enabled/disabled when appropriate. Sounds easy enough
but I'm running into a strange problem.

In the Form_Current event is the code:

If Me.CurrentRecord = Me.RecordsetClone.RecordCount Then
Me.cmdNextRecord.Enabled = False
Else
Me.cmdNextRecord.Enabled = True '**
End If

If I put a break point at '**, the code breaks when the form opens.
However, in break mode, I get the following from the immediate window:

?Me.CurrentRecord = Me.RecordsetClone.RecordCount
True

Is there some sort of timing issue here? The record source is not changing
(to my knowledge) in the OnCurrent event. If I put a break point before the
code, and step through slowly, it seems to work fine. I have a new(er) PC
that shouldn't have any problems with the forms record source query. Any
thoughts, suggestions, comments, or even snide remarks are wanted. Thanks in
advnace.


Yes, there is a timing issue here. Access only tries to
load the visible records immediately and schedules a
background task to get the reset of the records.

You can force Access to retrieve all the records (and make
the RecordCount reflect the total records by using the
MoveLast method.

Me.RecordsetClone.MoveLast
If . . .
 
D

DebbieG

I use this code with success:

Private Sub PrevNext()
On Error GoTo GotError
Dim count As Integer, position As Integer
position = Me.CurrentRecord
count = Me.RecordsetClone.RecordCount
If position = 1 Then
Me.cmdPrevious.Enabled = False
Me.cmdNext.Enabled = True
ElseIf position = count Then
Me.cmdPrevious.Enabled = True
Me.cmdNext.Enabled = False
Else
Me.cmdPrevious.Enabled = True
Me.cmdNext.Enabled = True
End If

ExitSub:
Exit Sub

GotError:
MsgBox Err.Number & vbCrLf & Err.Description
Resume ExitSub
End Sub

I've got "call PrevNext" in Form_Open, Form_Current, Form_AfterUpdate, and behind my Undo command button.

HTH,
Debbie


| Using Access 2000 (9.0.6926 SP3)
|
| I have a basic form used for viewing records. On this form are next and
| previous record buttons located at the top of the page. My client wants
| these buttons to be enabled/disabled when appropriate. Sounds easy enough
| but I'm running into a strange problem.
|
| In the Form_Current event is the code:
|
| If Me.CurrentRecord = Me.RecordsetClone.RecordCount Then
| Me.cmdNextRecord.Enabled = False
| Else
| Me.cmdNextRecord.Enabled = True '**
| End If
|
| If I put a break point at '**, the code breaks when the form opens.
| However, in break mode, I get the following from the immediate window:
|
| ?Me.CurrentRecord = Me.RecordsetClone.RecordCount
| True
|
| Is there some sort of timing issue here? The record source is not changing
| (to my knowledge) in the OnCurrent event. If I put a break point before the
| code, and step through slowly, it seems to work fine. I have a new(er) PC
| that shouldn't have any problems with the forms record source query. Any
| thoughts, suggestions, comments, or even snide remarks are wanted. Thanks in
| advnace.
|
 

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