Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6229839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:38:32+00:00 2026-05-24T09:38:32+00:00

im trying to get the next number in the autonumber sequence for the primary

  • 0

im trying to get the next number in the autonumber sequence for the primary key programatically. For instance, if the last number in the table was 10, i need it to return 11. Before, I would use something like:

docmd.RunCommand acCmdRecordsGoToNew

in order to tell the database to go to the next record, and then i’d assign it to a control on the form to show the user what record they are currently entering. The problem is, this function ceased to work when I disabled the navigation buttons by setting it’s property to “No” in the properties window. How do I get the next record in vba without the nav bar being enabled?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:38:33+00:00Added an answer on May 24, 2026 at 9:38 am

    To know what the real next value is, you have to look up the SeedValue for your Autonumber column. This code does that:

      Public Function GetSeedValue(strTable As String, strColumn As String) As Long
        Dim cnn As Object 'ADODB.Connection
        Dim cat As Object ' New ADOX.Catalog
        Dim col As Object ' ADOX.Column
    
        Set cnn = CurrentProject.Connection
        Set cat = CreateObject("ADOX.Catalog")
        cat.ActiveConnection = cnn
    
        Set col = cat.Tables(strTable).Columns(strColumn)
        GetSeedValue = col.Properties("Seed")
    
        Set col = Nothing
        Set cat = Nothing
        Set cnn = Nothing
      End Function
    

    If you’re going to call it a lot, you’d likely want to cache the ADOX Catalog object variable, rather than re-initialize it each time you call this function.

    Note that in a multiuser environment, this may or may not be accurate, since by the time you use it, it may have been updated by another user. However, it doesn’t have the problem with skipping Autonumber values that Max()+1 can have.

    Keep in mind, though, that if you care about the next Autonumber value, it means YOU’RE USING IT WRONG. Autonumber values are surrogate keys and you should never, ever care what the values are.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When trying to get next activities it shows this error: This page contains the
I'm trying to get a regexp to solve the next problem: I have some
I am trying to get an array of a date plus the next 13
I am just trying to get the auto incremented value of a table that
Im trying to get a certain number of searchresults append when making a search
Trying to get a simple COUNT from a table that takes a couple of
I'm trying to get the next and previous objects of a comic book issue.
I'm trying to get a random number generator working on the iPhone. There are
I'm trying to get the first day of the next quartal, for example now
I am trying to get the bold text next to the hour scheldule (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.