Get return PK value from SQL

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What is the best way to get a primaryKey value back from SQL when adding a
record to a subform? I need the PK of the new subform record to pass on to
other code.

Thanks!!
 
How are you adding the record? Are you running it via code? are you opening
a recordset and then adding a record? Tell us more....
 
I could add the record via code, but currently was just using the Access
subform built-in functionality. If I use code, would I run that on "Before
Insert"?
 
Is the primary key field in the subform's RecordSource query? If it is, you
should be able to read its value during the form's BeforeUpdate event, or
during the form's Dirty event, assuming that it's an autonumber field.
 
Wow! That really helped! The PK was in the recordsource. I put

Me.Dirty=False

to commit the edit as the first line in the AfterUpdate event of the field
the user was entering data on, and my PK value is there. How simple. I can't
tell you how hours of headaches this has caused and to think all that time
was wasted!
 
Back
Top