A
akhosravi4703
I have an access database that I am scaling up to an Oracle database
via ODBC connection. I've run into a problem capturing the ID column
of a newly created record. I need this ID to populate the FK of
dependent related rows in another table that I am generating at the
same time.
I used to use the following code when using just Access in the past
Dim db as database, rst as recordset, x as long
Set db = currentdb
set rst = db.openrecordset("SELECT * FROM tblMyParentTable")
rst.addnew
rst!Field1 = value1
rst!Field2 = value2
x = rst!IdentityField
rst.update
set rst = db.openrecordset("SELECT * FROM tblMyChildTable")
rst.addnew
rst!FK = X
rst!FieldA = valueA
rst.update
Worked fine so long as you set the X variable before the update
command because Access reserves the new auto number before insertion.
However, this doesn't work with Oracle as the sequence is apparently
not generated until after insertion.
I've been searching all night for the answer, but it seems everything
on the web tells you how to do this when using SQLServer with the
@@Identity method, which won’t work here. I've seen only vague answers
to this with Oracle.
Here's the rub. It will not be practical to write any triggers or
stored procedures within Oracle to do this. I don't have privileges to
do that, nor the time to wait for a DBA to do it. Is there some way I
can do this without cheese balling it using some flavor of max of
identity column?
via ODBC connection. I've run into a problem capturing the ID column
of a newly created record. I need this ID to populate the FK of
dependent related rows in another table that I am generating at the
same time.
I used to use the following code when using just Access in the past
Dim db as database, rst as recordset, x as long
Set db = currentdb
set rst = db.openrecordset("SELECT * FROM tblMyParentTable")
rst.addnew
rst!Field1 = value1
rst!Field2 = value2
x = rst!IdentityField
rst.update
set rst = db.openrecordset("SELECT * FROM tblMyChildTable")
rst.addnew
rst!FK = X
rst!FieldA = valueA
rst.update
Worked fine so long as you set the X variable before the update
command because Access reserves the new auto number before insertion.
However, this doesn't work with Oracle as the sequence is apparently
not generated until after insertion.
I've been searching all night for the answer, but it seems everything
on the web tells you how to do this when using SQLServer with the
@@Identity method, which won’t work here. I've seen only vague answers
to this with Oracle.
Here's the rub. It will not be practical to write any triggers or
stored procedures within Oracle to do this. I don't have privileges to
do that, nor the time to wait for a DBA to do it. Is there some way I
can do this without cheese balling it using some flavor of max of
identity column?