@@identity

E

enrico

how do you use @@identity? i read it somewhere and it could be helpful on my
code. how can i insert it on my INSERT statement?
 
D

Danny J. Lesandrini

@@IDENTITY is a SQL Server feature, not an Access one.

What exactly are you hoping to accomplish with it?

Some use @@IDENTITY in stored procs to retrieve the last
generated "Autonumber" and return it to the calling proc, but
it's not always perfect. If your proc inserts into a table that has a
trigger that inserts into another table with another autonumber,
then @@IDENTITY will return the second autonumber, This
causes problems. There's a different SQL Server keyword
that should be used in place of this ... I forget offhand what it is.
 
D

Danny J. Lesandrini

Well! I'll be darned!

That's why I still read the newsgroup. Never stop learning new things about Access.
 
E

enrico via AccessMonster.com

i look at the link that was attach and i barley grasp the idea. i want to
insert the newly generated auto-increment ID to the foreign key of my other
table to link the two tables. i have to tables, namely: tblGenInfo and
tblResult which is link through my "GIID". i created their form(only one for
two tables) though design view and the INSERT statement is hard coded. when
it comes to saving data(only one button for both) to my tblResult i don't
know how to insert the newly generated "GIID" from tblGenInfo into tblResult.
can anyone help or give a sample on how to do this?
 
J

John W. Vinson

i look at the link that was attach and i barley grasp the idea. i want to
insert the newly generated auto-increment ID to the foreign key of my other
table to link the two tables. i have to tables, namely: tblGenInfo and
tblResult which is link through my "GIID". i created their form(only one for
two tables) though design view and the INSERT statement is hard coded. when
it comes to saving data(only one button for both) to my tblResult i don't
know how to insert the newly generated "GIID" from tblGenInfo into tblResult.
can anyone help or give a sample on how to do this?

By FAR the simplest way to do this is to use a Form based on tblGenInfo with a
Subform based on tblResult, using GIID as the master/child link field. Add a
record to the main form; that will populate its GIID. Add a record to the
child form; it will inherit the mainform's GIID.

Creating empty "placeholder" records in code is far more complex and generally
unnecessary.
 
E

enrico via AccessMonster.com

i've gone far already and if i create a new form again and use what u said
i'll go back to start again. i just thought it could be possible to just use
something like last inserted ID
 
J

John W. Vinson

i've gone far already and if i create a new form again and use what u said
i'll go back to start again. i just thought it could be possible to just use
something like last inserted ID

You can; in my opinion restructuring the form will be easier. I may well be
wrong, since I know nothing about your form. Your choice!
 
W

wisepin

something like

dim mydb as database
set mydb=currentdb
mydb.execute "insert into tblResult (GIID ,otherfieldname,...)select
@@IDENTITY as GIID ,othervalue as otherfieldname,...."
 
Top