By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,261 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,261 IT Pros & Developers. It's quick & easy.

Disabling buttons on form - End of recordset

P: 2
In order to disable the previous and next buttons on my form, I followed the attached code. The buttons seem to work fine except for one thing. When the form first opens, the next button is disabled; however, if you click on the forward arrow on the scroll bar and click the previous button which takes you back to the 1st form, the next button is now enabled!

What am I doing wrong?

I just need the next button to be ENABLED when I open the form.

My code reads as follows:

This code is located on the form's properties "OnCurrent"

Private Sub Form_Current()
If (Me.Recordset.AbsolutePosition = Me.Recordset.RecordCount - 1) Or (Me.NewRecord) Then
btnNext.Enabled = False
Else
btnNext.Enabled = True
End If
If Me.Recordset.AbsolutePosition = 0 And Not Me.NewRecord Then
btnPrevious.Enabled = False
Else
btnPrevious.Enabled = True
End If


End Sub


This code is located on the form's button - btnPrevious "onclick"

Private Sub btnPrevious_Click()
On Error GoTo Err_btnPrevious_Click

' Valideer en werk boeknummer-boekhouding bij
If ValidatiesNotOK Then
Exit Sub
End If
DoCmd.GoToRecord , , acPrevious

Exit_btnPrevious_Click:
Exit Sub

Err_btnPrevious_Click:
If Err.Number = 2105 Then
Resume Exit_btnPrevious_Click
Else
MsgBox Err.Number & " " & Err.Description
End If
Resume Exit_btnPrevious_Click
End Sub

This code is located on the form's button - btnNext"onclick"


Private Sub btnNext_Click()
On Error GoTo Err_btnNext_Click

' Valideer en werk boeknummer-boekhouding bij
If ValidatiesNotOK Then Exit Sub

Me.RecordsetClone.MoveNext
If Me.RecordsetClone.EOF Then
Exit Sub
End If
DoCmd.GoToRecord , , acNext

Exit_btnNext_Click:
Exit Sub

Err_btnNext_Click:
MsgBox Err.Number & " " & Err.Description
Resume Exit_btnNext_Click

End Sub
Oct 3 '06 #1
Share this Question
Share on Google+
1 Reply


PEB
Expert 100+
P: 1,418
PEB
Hi,

I think that the problem is in the use of Recordcount property

See this:

Use the RecordCount property to find out how many records in a Recordset or TableDef object have been accessed. The RecordCount property doesn't indicate how many records are contained in a dynaset-, snapshot-, or forward-only–type Recordset object until all records have been accessed. Once the last record has been accessed, the RecordCount property indicates the total number of undeleted records in the Recordset or TableDef object. To force the last record to be accessed, use the MoveLast method on the Recordset object. You can also use an SQL Count function to determine the approximate number of records your query will return.

Note Using the MoveLast method to populate a newly opened Recordset negatively impacts performance. Unless it is necessary to have an accurate RecordCount as soon as you open a Recordset, it's better to wait until you populate the Recordset with other portions of code before checking the RecordCount property.

As your application deletes records in a dynaset-type Recordset object, the value of the RecordCount property decreases. However, records deleted by other users aren't reflected by the RecordCount property until the current record is positioned to a deleted record. If you execute a transaction that affects the RecordCount property setting and you subsequently roll back the transaction, the RecordCount property won't reflect the actual number of remaining records.

The RecordCount property of a snapshot- or forward-only–type Recordset object isn't affected by changes in the underlying tables.

A Recordset or TableDef object with no records has a RecordCount property setting of 0.

When you work with linked TableDef objects, the RecordCount property setting is always –1.

Using the Requery method on a Recordset object resets the RecordCount property just as if the query were re-executed.
Oct 8 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.