S
sturose2000
Hi all,
I'd like to be able to append a new record into an existing table, where the
data for the record comes from earlier in the VBA code; then I need to find
the Primary Key field for the record I just added.
I have code that adds a new record to a table:
DoCmd.RunSQL "INSERT INTO " & strTbl & " (InterventionCode) VALUES ('" &
strLabel & "');"
lngIntID = DLookup("[InterventionAutoID]", strTbl, "[InterventionCode] =
'" & strLabel & "'")
Here, strTbl and strLabel are arguments of the function in which this code
is found. The field strTbl.InterventionAutoID is an AutoNumber type with
random value, not sequential.
The second line of code has been fine for cases where strLabel is unique,
that is, does not duplicate any existing strTbl.InterventionCode. However, I
now have cases where InterventionCode is not unique so I cannot count on
DLookup to return the "true new" InterventionAutoID.
Any help grabbing the "correct" number for lngIntID?
Thanks in advance,
Stu
I'd like to be able to append a new record into an existing table, where the
data for the record comes from earlier in the VBA code; then I need to find
the Primary Key field for the record I just added.
I have code that adds a new record to a table:
DoCmd.RunSQL "INSERT INTO " & strTbl & " (InterventionCode) VALUES ('" &
strLabel & "');"
lngIntID = DLookup("[InterventionAutoID]", strTbl, "[InterventionCode] =
'" & strLabel & "'")
Here, strTbl and strLabel are arguments of the function in which this code
is found. The field strTbl.InterventionAutoID is an AutoNumber type with
random value, not sequential.
The second line of code has been fine for cases where strLabel is unique,
that is, does not duplicate any existing strTbl.InterventionCode. However, I
now have cases where InterventionCode is not unique so I cannot count on
DLookup to return the "true new" InterventionAutoID.
Any help grabbing the "correct" number for lngIntID?
Thanks in advance,
Stu