T
Tim
Say I have a table named table1 with the following fields (for simplicity)
ID - autonumber
field1 - text
I have a form that allows the user to enter a value in for field1 and checks
to make sure it is valid. I then append this record to table1 using
INSERT INTO table1 ( field1 ) VALUES ( strvar )
in vba using an adodb.command line to .execute the sql statement. Now, I
want to get the autonumber ID value for this newly added record. Is there a
way to do it without querying the table on the value that was just entered? I
assume that I can't just grab the last record that was just appended because
multiple users could possibly append at the same (almost same) time and I
could grab the wrong ID. Also, there is a possibility that field1 has the
same value in it, so if I matched on that, I could possibly grab the wrong ID
again.
The reason I want to get the autonumber ID is because I have a second table
that has a relationship with this field. So, I have to add this first table
to get the autonumber ID and then add that autonumber ID to the 2nd table
(Along with other values) to create a complete account of what is on the
form.
Or is there an easier way than how I am going about this? I have a form that
has header and footer information in it and then the middle of the form has 4
groups of data that has all the same fields, but either different data or no
data at all. But, at most, there are only 4 groups of data. So, I decided to
create one table that has all the header and footer information in it along
with 4 fields that link to the other table. And the 2nd table has 1 instance
of the 4 groups of data along with the autonumber ID field. So, I want to be
able to check to see if there is data inputted, then I save it and get the
autonumber ID to link it back to the header and footer information. If there
is no data, then I do not add a record to the 2nd table and link that field
in the 1st table to a blank record in the 2nd table. Then, later, if they add
information to a group that was previously blank, I will add that record and
link its autonumber id up with that field. (I hope that made sense.)
Any help or suggestions are much appreciated!
Tim
ID - autonumber
field1 - text
I have a form that allows the user to enter a value in for field1 and checks
to make sure it is valid. I then append this record to table1 using
INSERT INTO table1 ( field1 ) VALUES ( strvar )
in vba using an adodb.command line to .execute the sql statement. Now, I
want to get the autonumber ID value for this newly added record. Is there a
way to do it without querying the table on the value that was just entered? I
assume that I can't just grab the last record that was just appended because
multiple users could possibly append at the same (almost same) time and I
could grab the wrong ID. Also, there is a possibility that field1 has the
same value in it, so if I matched on that, I could possibly grab the wrong ID
again.
The reason I want to get the autonumber ID is because I have a second table
that has a relationship with this field. So, I have to add this first table
to get the autonumber ID and then add that autonumber ID to the 2nd table
(Along with other values) to create a complete account of what is on the
form.
Or is there an easier way than how I am going about this? I have a form that
has header and footer information in it and then the middle of the form has 4
groups of data that has all the same fields, but either different data or no
data at all. But, at most, there are only 4 groups of data. So, I decided to
create one table that has all the header and footer information in it along
with 4 fields that link to the other table. And the 2nd table has 1 instance
of the 4 groups of data along with the autonumber ID field. So, I want to be
able to check to see if there is data inputted, then I save it and get the
autonumber ID to link it back to the header and footer information. If there
is no data, then I do not add a record to the 2nd table and link that field
in the 1st table to a blank record in the 2nd table. Then, later, if they add
information to a group that was previously blank, I will add that record and
link its autonumber id up with that field. (I hope that made sense.)
Any help or suggestions are much appreciated!
Tim