By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,709 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

Access 2002 Auto numbering key

P: n/a
Hello,

Here is a basic question (I am an access dummy).

I create an object in a table where the key is an auto num and
therefore I do not specify the Id I my VBScript code:
qryCreation.Parameters(strParamModelName).Value = strPNDBName
qryCreation.Parameters(strParamEMI).Value = strValues(2)
qryCreation.Parameters(strParamFatherId).Value = strValues(3)
qryCreation.Parameters(strParamBlockDiagramPartId) .Value =
objDictionnaryBlockDiagramIdToName(cstBlockDiagram NamePrefix &
strValues(4))

Err.clear
On Error Resume Next
qryCreation.Execute dbFailOnError
....

How can I get the computed Id (auto num) ?

Thanks in advance

Jul 6 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In JET 4 (Access 2000 and later), you can ask for the @@IDENTITY value of
the most recently executed action query.

Example:

Function ShowIdentity() As Variant
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = DBEngine(0)(0)
db.Execute "INSERT INTO MyTable ( MyField ) SELECT 'nuffin' AS Expr1;"

Set rs = db.OpenRecordset("SELECT @@IDENTITY AS LastID;")
ShowIdentity = rs!LastID
rs.Close

Set rs = Nothing
Set db = Nothing
End Function
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<ch***************@laposte.netwrote in message
news:11**********************@75g2000cwc.googlegro ups.com...
Hello,

Here is a basic question (I am an access dummy).

I create an object in a table where the key is an auto num and
therefore I do not specify the Id I my VBScript code:
qryCreation.Parameters(strParamModelName).Value = strPNDBName
qryCreation.Parameters(strParamEMI).Value = strValues(2)
qryCreation.Parameters(strParamFatherId).Value = strValues(3)
qryCreation.Parameters(strParamBlockDiagramPartId) .Value =
objDictionnaryBlockDiagramIdToName(cstBlockDiagram NamePrefix &
strValues(4))

Err.clear
On Error Resume Next
qryCreation.Execute dbFailOnError
...

How can I get the computed Id (auto num) ?

Thanks in advance

Jul 6 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.