Assuming the query is instantiated as a recordset of some type, it will have a property "EOF" When this property becomes "true", set the enabled property of the button to false.
Assigning the recordset the "name" [rst] and the button the "name" [cmdNext], the code would be something like"
Private Sub cmd_Next_Click
[tab]rst.MoveNext
[tab]If (rst.Eof) Then
[tab][tab]Me.cmdNext.Enabled = False
[tab]End If
MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
I am having a similar problem, except with a form. I have a textbox that is bound to a field in my table. I am creating my own navigation buttons and I want to display a msgbox saying "you've reached the end of the list" when the user is at the end of the recordset. I tried using the code:
Private Sub cmdNext_Click()
If (Me.Recordset.MoveNext.EOF=True) Then
Msgbox ("end of list!!"
Else
DoCmd.GoToRecord , , acNext
End If
End Sub
However, I keep getting the error message that an object is required. Any ideas? Thanks!!
As per your message, simply put some error handling code into your code for cmdNext. When it reaches the end of file it will call the end of file error.
All you would need is
Private Sub cmdNext_Click()
On Error goto Err_cmdNext_Click
<<<< Your normal code goes here to move to next file. >>>
Exit Sub
Err_cmdNext_Click:
MsgBox "You have reached the end of file.", vbOkOnly, "End of File"
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.