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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you disable a button in a form when it reach the end of record? 2

Status
Not open for further replies.

cctrinh

MIS
Feb 2, 2001
25
US
I have a form that display the query result. I want to disable a button when i get to the end of the query. Please help!!!!

Thank you,
 
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
 
However do not forget to move the focus to another control before attempting to disable the control that fired the event.
 
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 &quot;You have reached the end of file.&quot;, vbOkOnly, &quot;End of File&quot;

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top