473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

last id of auto-increment field

Hello,
How can I find the last indentity of auto-increment field ?
(If I inserted a record, then the auto-increment field is build
automatically,
and I want to find its value).

Thanks :)
May 24 '06 #1
9 15235
On Wed, 24 May 2006 16:17:36 +0200, "Eitan M"
<no_spam_please@nospam_please.com> wrote:

Depends on how you are inserting. How?

-Tom.

Hello,
How can I find the last indentity of auto-increment field ?
(If I inserted a record, then the auto-increment field is build
automatically,
and I want to find its value).

Thanks :)


May 24 '06 #2
Let say this is the structure of your table
ID,Field1,Field2,Field3 and ID is the
auto incremented field.
INSERT INTO
TABLENAME(Field1,Field2,Field3)
VALUES(xxx,yyy,zzz)

after passing insert statement above,
you can query the ID of that record
by
SELECT ID FROM TABLE
WHERE
Field1 = xxx and
Field2 = yyy and
Field3 = zzz

HTH

May 25 '06 #3
On 24 May 2006 20:21:17 -0700, ar********@gmail.com wrote:

Only if those 3 fields refer to a unique record. That's why I asked
for details. OP could be doing a rs.AddNew, or enter a record
interactively, or ...

-Tom.
Let say this is the structure of your table
ID,Field1,Field2,Field3 and ID is the
auto incremented field.
INSERT INTO
TABLENAME(Field1,Field2,Field3)
VALUES(xxx,yyy,zzz)

after passing insert statement above,
you can query the ID of that record
by
SELECT ID FROM TABLE
WHERE
Field1 = xxx and
Field2 = yyy and
Field3 = zzz

HTH


May 25 '06 #4
what if those 3 fields didnt refer to a unique record?

If that would b the case then he use this instead

SELECT MAX(ID) FROM TABLE
WHERE
Field1 = xxx and
Field2 = yyy and
Field3 = zzz

but what if 2 users inserted same record at the same time,
in that case i give up. I dont have anymore idea how to get that
ID.

if he is using Recordset, after he pass an update method he can sort
that
recordset DESC with respect to that autoincremented field. He is very
sure
that the last record is the last added record.

May 25 '06 #5
Isn't any global field, such as last_identity (something simmiliar is in
sql-server) ?

Thanks :)
May 25 '06 #6
in sql server you can retrieve the ID of the
newly added record using
@@IDENTITY,
SCOPE_IDENTITY or
IDENT_CURRENT

but those function dont have
equivalent in Access.

May 25 '06 #7
rkc
Tom van Stiphout wrote:
On 24 May 2006 20:21:17 -0700, ar********@gmail.com wrote:

Only if those 3 fields refer to a unique record. That's why I asked
for details. OP could be doing a rs.AddNew, or enter a record
interactively, or ...


If all the fields in a record do not make it unique then what
difference would it make which record with those three values was retrieved?
May 25 '06 #8
ar********@gmail.com wrote in news:1148550848.023918.189660
@g10g2000cwb.googlegroups.com:
in sql server you can retrieve the ID of the
newly added record using
@@IDENTITY,
SCOPE_IDENTITY or
IDENT_CURRENT

but those function dont have
equivalent in Access.


Jet OLE DB Provider Version 4.0 Supports SELECT @@Identity

A simple way to use this is to INSERT with a distinct ADODB Connection.

Sub temp()
Dim c As ADODB.Connection
Set c = New ADODB.Connection
With c
..ConnectionString = CurrentProject.BaseConnectionString
..Open
..Execute "INSERT INTO [Order Details] " _
& "(OrderID, ProductID, UnitPrice, Quantity, Discount) " _
& "Values (12, 23, 15.5, 12, 3/1000)"
Debug.Print .Execute("SELECT @@Identity").Collect(0)
' prints the autonumber of the newly inserted record
..Close
End With
Set c = Nothing
End Sub

--
Lyle Fairfield
May 25 '06 #9
Lyle is correct.

May 25 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: porterboy | last post by:
Hi Folks, I have auto-completion set up in my python interpreter so that if I hit the tab key it will complete a variable or a python command*. eg. if I type >>> imp and if I then hit the tab...
5
by: Robert Downes | last post by:
I'm using the following in a page that I'm testing in Mozilla: p.actionLinkBlock {border: 1px #000000 dashed; padding: 0.2cm; width: auto} But the dashed border is extending to the right-edge...
1
by: Thomas Leggett | last post by:
I am trying to use jet/access to store my data but I need some feedback from the database. I have a table that has an auto-number as a primary-key, so when I insert a post into the table the ID...
5
by: SalimShahzad | last post by:
dear gurus, can any one help me to how to store progrmatically last value in combo box. say i load access form. but in combo box the last value how it will come any ideas...as i need only...
5
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the...
15
by: Bill Pursell | last post by:
The faq (question 1.12) states that the keyword "auto" is completely useless. However, it is necessary to forward declare a nested function (for gcc...I'm not sure if this is gcc specific or a...
3
by: S.Dickson | last post by:
I had an access database that i use as an ordering system. I have a form for entering customer details. When i add a new customer on the form the customer number is an auto number that appears when...
4
by: Mr. Wilson | last post by:
On this page (just a demo) I can’t get IE6 to auto-select the first item in the dynamically-generated drop-down menus. Well, that isn’t entirely true. Sometimes it works properly, but never on the...
1
by: glasssd | last post by:
Hi, I was hoping someone might have some ideas on how I can hack around a problem I'm having with the auto-complete feature of the ComboBox. I have a data entry application that uses a pair of...
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.