Prevent Next Record command button from advancing MS Access

Posted on 2012-09-08
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.
Question by:dbfromnewjersey
    LVL 29

    Accepted Solution

    Use this code instead for your OnClick event of the Next Record button:
    If Me.Recordset.EOF Then MsgBox "This is the last record."

    Open in new window


    Author Comment

    Thank you.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    This article is a continuation or rather an extension from Cascading Combos ( and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
    QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
    In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now