G
George Hoyt via AccessMonster.com
The following code snipit adds TWO records to the table?
****************************************************
Dim objMyCon As Object
Dim objMyRS As Object
Dim fldLnkData As Long
Set objMyCon = Application.CurrentProject.Connection
Set objMyRS = CreateObject("ADODB.Recordset")
'
' Set up and save all the data just entered on the form
'
objMyRS.Open "tblPlayers", objMyCon, adOpenStatic, adLockOptimistic,
adCmdTable
If objMyRS.Supports(adAddNew) Then
objMyRS.AddNew
objMyRS!txtLastName = Me![txtLastName]
objMyRS!txtFirstName = Me![txtFirstName]
objMyRS!txtMiddleInitial = Me![txtMiddleInitial]
objMyRS.Update
End If
fldLnkData = objMyRS!ctrPlayerID ' Get the Primary
Key for this record
objMyRS.Close
************************************************
The goal is to add the data to tblPlayers and retrieve the Autoincrement
Primary Key and use it for creating additional tables with this value as
the foreign key. This works, EXCEPT it adds a record, then ADDS it again
and the variable fldLnkData ends up with the SECOND added row? I've tried
using an "INSERT ..." SQL, and NUMEROUS other ways to stop this and I
can't. On the other hand, the following snipit is used to Add the foreign
key to a table for later use, and it gets added correctly ... i.e., no
duplication.
*********************************************** objMyRS.Open
"tblPlayerAddresses", objMyCon, adOpenKeyset, adLockOptimistic, adCmdTable
If objMyRS.Supports(adAddNew) Then
objMyRS.AddNew
objMyRS!lnkPlayerID = fldLnkData
objMyRS.Update
End If
objMyRS.Close
********************************************************
At a loss .. just can't figure it out?? Is it related to the Autoincrement
somehow?
****************************************************
Dim objMyCon As Object
Dim objMyRS As Object
Dim fldLnkData As Long
Set objMyCon = Application.CurrentProject.Connection
Set objMyRS = CreateObject("ADODB.Recordset")
'
' Set up and save all the data just entered on the form
'
objMyRS.Open "tblPlayers", objMyCon, adOpenStatic, adLockOptimistic,
adCmdTable
If objMyRS.Supports(adAddNew) Then
objMyRS.AddNew
objMyRS!txtLastName = Me![txtLastName]
objMyRS!txtFirstName = Me![txtFirstName]
objMyRS!txtMiddleInitial = Me![txtMiddleInitial]
objMyRS.Update
End If
fldLnkData = objMyRS!ctrPlayerID ' Get the Primary
Key for this record
objMyRS.Close
************************************************
The goal is to add the data to tblPlayers and retrieve the Autoincrement
Primary Key and use it for creating additional tables with this value as
the foreign key. This works, EXCEPT it adds a record, then ADDS it again
and the variable fldLnkData ends up with the SECOND added row? I've tried
using an "INSERT ..." SQL, and NUMEROUS other ways to stop this and I
can't. On the other hand, the following snipit is used to Add the foreign
key to a table for later use, and it gets added correctly ... i.e., no
duplication.
*********************************************** objMyRS.Open
"tblPlayerAddresses", objMyCon, adOpenKeyset, adLockOptimistic, adCmdTable
If objMyRS.Supports(adAddNew) Then
objMyRS.AddNew
objMyRS!lnkPlayerID = fldLnkData
objMyRS.Update
End If
objMyRS.Close
********************************************************
At a loss .. just can't figure it out?? Is it related to the Autoincrement
somehow?