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