Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form navigation buttons not working

Status
Not open for further replies.

BillyL

IS-IT--Management
Jul 18, 2000
91
US
I have created navigation buttons in a form to move to First, Next, Previous, Last and New records. I want to disable certain buttons when certain records are current. I am having difficulty with the Last button. When I click it, I want the Next button to be disabled but it remains enabled.
Here is a summary of the code:
Declarations:
Dim recClone as Recordset
Set recClone = Me.RecordsetClone()

I have tried two different codes to make this happen:
1)
recClone.MoveNext
If recClone.EOF = True Then
cmdNext.Enabled = False
Else
cmdNext.Enabled = True
End If
recClone.MovePrevious

2)
recClone.MoveNext
cmdNext.Enabled = Not (recClone.EOF)
recClone.MovePrevious

I get the same results from both codes: the cmdNext button is not disabled.

With the cmdFirst button I use this code:
recClone.MovePrevious
If recClone.BOF = True Then
cmdPrevious.Enabled = False
Else
cmdPrevious.Enabled = True
End If
reClone.MoveNext

This code successfully disables the cmdPrevious button. The only thing I can think of is that there is a blank record after the last record which is essetially a new record and I wonder if that has anything to do with the problem.

I wrote code to disable the cmdNext button when I click on the cmdNew button and that works correctly.

I got the code from a programming book and it works perfect in the example database they use (of course).

Any ideas??
 
The clone recordset is not in sync with the form. Use the bookmark of the form's recordset to set the bookmark on the clone rset then use the move method which should get your clone to EOF and then it should disable the button.
 
it should look like this:

Private Sub Form_Current()
Dim recClone As Recordset
Set recClone = Me.RecordsetClone()
recClone.Bookmark = Me.Bookmark
recClone.MoveNext
cmdNext.Enabled = Not (recClone.EOF)
recClone.MovePrevious
End Sub

I tried it with your second approach for the button.
 
Thanks! Your suggestion worked. I synchronised the recordset and form before the cmdHome button but not before the cmdEnd button. I figured once it is sync'ed then it stays sync'ed. I placed the
recClone.Bookmark = Me.Bookmark
code immediately before the cmdLast code and it worked fine.

Thanks again!

This site is the greatest!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top