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

Exception for "Next Record" command button

Status
Not open for further replies.

KerryL

Technical User
May 7, 2001
545
US
A number of the forms in my database contain command buttons that allow users to go to the next record when the button is clicked. However, if the last record is being viewed and the "Next Record" cmd button is clicked, a blank form is displayed.

Is it possible to modify the "on click" code so that if the last record is being displayed and the Next Record cmd button is clicked, the user won't see a blank form?

Can I add a disply message that says "No more records" and also not show a blank form?

Thanks in advance for your help,
KerryL
 
Why not totally disable the button if you are on the last one (or the first one for that matter.) The below code will disable the Previous button if you are on the first record and disables the Next button if you are on the last. Just place this in the Form's OnCurrent Event and change the button names to match yours...


Dim rs As Recordset
Set rs = Me.RecordsetClone
rs.Bookmark = Me.Bookmark
rs.MovePrevious
Me![Previous].Enabled = Not rs.BOF
rs.Bookmark = Me.Bookmark
rs.MoveNext
Me![Next].Enabled = Not rs.EOF
Programming isn't a profession of choice.
It's a profession of calling...
"Hey Programmer, your application broke again!" [spin]

Robert L. Johnson III, A+, Network+, MCP
robert.l.johnson.iii@citi.com
 
I thought of that but wasn't sure how to do it. Thank you Robert, I'll give it a try.
 
If it is a bound form and you are using the docmd.gotorec function then you can do the following.

Alter the form so that the users can not add a new record,
(you can put a button on the form to allow them to add later).
Now when they get to the last record and press the button an error will occur, on the buttons onclick event capture this error and display the error message that you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top