Re: ADO AddNew Method creates TWO Records
From: George Hoyt via AccessMonster.com (forum_at_AccessMonster.com)
Date: 02/03/05
- Next message: Brendan Reynolds: "Re: Passing values into DoCmd.RunSQL"
- Previous message: Foss: "Re: Splitting contents of a field"
- In reply to: George Hoyt via AccessMonster.com: "Re: ADO AddNew Method creates TWO Records"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 03 Feb 2005 14:57:14 GMT
Chris
Thanks for taking the time to evaluate. Strangely, I've experienced BOTH
... my original problem of adding 2 records AND the skipping of
autoincrement #'s. I thought if I solved ONE, I'd inherently solve both.
I tried the following code rather than the .AddNew and it seems to work
fine ...
The first command is the command that is created if you add a command
button to your form and answer the wizard questions to Add Record. Then I
opened the table to get the Primary Key for the last entry for use as
foreign keys in other tables. Of course I make the assumption that the
last entry I make is in fact the last record!!
Not certain what is peculiar about the .AddNew when using form controls for
data entry?
**************************************************
DoCmd.GoToRecord , , acNewRec
'
' Get the primary key of the record just added
'
objMyRS.Open "tblPlayers", objMyCon, adOpenStatic, adLockOptimistic,
adCmdTable
objMyRS.MoveLast
fldLnkData = objMyRS!ctrPlayerID ' Get the Primary
Key for this record
objMyRS.Close
'
' Set the foreign key in the related tables
'
objMyRS.Open "tblPlayerAddresses", objMyCon, adOpenKeyset,
adLockOptimistic, adCmdTable
If objMyRS.Supports(adAddNew) Then
objMyRS.AddNew
objMyRS!lnkPlayerID = fldLnkData
objMyRS.Update
End If
objMyRS.Close
***********************************************
Again, thanks for our help. Not sure what's going on, but this method of
doing what I'm trying to do will work ... I hope :>)
George
-- Message posted via http://www.accessmonster.com
- Next message: Brendan Reynolds: "Re: Passing values into DoCmd.RunSQL"
- Previous message: Foss: "Re: Splitting contents of a field"
- In reply to: George Hoyt via AccessMonster.com: "Re: ADO AddNew Method creates TWO Records"
- Messages sorted by: [ date ] [ thread ]