?
Solved

Prevent Next Record command button from advancing MS Access

Posted on 2012-09-08
2
Medium Priority
?
1,235 Views
Last Modified: 2012-09-08
I have an access form with a textbox on it that displays the [record number] field from MyTable.  I also have a Next Record command button on the form. Currently, the Next Record button is using the macro code that is automatically generated when you place a command button on a form.  I have 10 records in my table.  If I repeatedly click the button, it advances through the records. When I am on record 10 and click the Next Record button, it advances to the next record (a blank record) without a message. If I click the Next Record button again, then an error message pops up indicating "You can't go to the specified record".  I don't want this.  What I want is for the program to not advance past record 10. So, let's say I'm on record 10 and I click the Next Record button. It's there that I want a message to pop up saying something like "You have reached the last record" or whatever and for it to stay on record 10. I don't want it advancing beyond record 10 (or if I change the number of records, the last record in the table that has data in it).  Thanks.
0
Comment
Question by:dbfromnewjersey
2 Comments
 
LVL 29

Accepted Solution

by:
IrogSinta earned 1200 total points
ID: 38380356
Use this code instead for your OnClick event of the Next Record button:
Me.Recordset.MoveNext
If Me.Recordset.EOF Then MsgBox "This is the last record."

Open in new window

0
 

Author Comment

by:dbfromnewjersey
ID: 38380387
Thank you.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question