Solved

Access AutoIncrement Fields

Posted on 2002-05-03
7
311 Views
Last Modified: 2010-05-02
Hi guys,

I have a table in Access 97, this table have an Autoincrement field, i need to get the number of the next Increment. E.G. I have 3 rows in my table, so when i put one more row, it´ll receive number 4 in the database. I need the next value before inserting new data to the table, or after i´ve inserted the data.

I need to get from the access this Number, i´ll apreciate any help ;)



0
Comment
Question by:agamemnon
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 100 total points
ID: 6988927
Depending on your Cursor Type and Cursor Location (if you are using a recordset to update) this value may not be available directly with Access 97, so you may have to resort to doing something like:

Select Max(ID) + 1 As LastID From Table1

before you update or:

Select Max(ID) + 1 As LastID From Table1

after you update.

This has complications when this database can be hit by multiple users.

Anthony
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6988930
It is also dependant on the provider.  Are you using the Jet 4.0 provider?


Anthony
0
 
LVL 5

Expert Comment

by:rkot2000
ID: 6988962


HOWTO: Return Record's Autonumber Value Inserted into Access DB (Q221931)

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q221931

HOWTO: Implement Multiuser Custom Counters in Jet 4.0 and ADO 2.1 (Q240317)
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q240317
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:RichW
ID: 6988963
Why not run a SQL statement like "Select MAX(autonumberfieldname) FROM TableName" right after you insert the new record?



0
 
LVL 4

Expert Comment

by:RichW
ID: 6988966
Ooops.  Sorry guys.  I didn't read the MAX suggestions already entered.  My bad.
0
 

Author Comment

by:agamemnon
ID: 6991914
Thank you Guys, it´ll help me a lot...

The Max(Field) AFTER the new row was inserted solved my problem...
0
 

Author Comment

by:agamemnon
ID: 6991919
Thank you,

The problem was Solved with your suggestion of using MAX after inserting the row, i Am using ADO and jet4.0 provider :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

896 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

19 Experts available now in Live!

Get 1:1 Help Now