R
rhinoman
In an adp project, I am trying to do 2 table inserts, one to the client or
parent table, then another insert to a related or child table. both tables
are newly created and empty
The first insert works fine, but the second insert gives the following error
INSERT statement conflicted with COLUMN FOREIGN KEY constraint
'FK_ClientSW_Table_ClientTable'. The conflict occurred in database 'CGP',
table 'ClientTable', column 'id'. I
I made i diagram linking the two tables on
ClientTable.id ->ClientSW_Table.ClientId. Does that actually create the
entity relation?
but if I stop the app, and then attempt to do the second write again, using
the same code, it works.
Here is some of the relevant code:
Set cmd = CreateObject("Adodb.Command")
cmd.ActiveConnection = Application.CurrentProject.Connection
strCMD = "Insert into ClientTable(LastName,FirstName) values('" + sLastName
+ "','" + sFirstName + "')"
cmd.CommandText = strCMD
cmd.Execute , nrecs
'get the ClientId value for the newly added record
strSQL = "select max(ClientId) from tbl_CLIENTS"
Set RS = CreateObject("Adodb.RecordSet")
RS.Open strSQL, Application.CurrentProject.Connection, 1 ' 1 =
adOpenKeyset
NewClientRecId = RS(0)
RS.Close
Set RS = Nothing
strCMD = "Insert into ClientSW_Table(ClientId,SWid) VALUES(" +
Str(NewClientRecId) + "," + sSWID + ")"
cmd.CommandText = strCMD
cmd.Execute , nrecs 'This fails
How should I be doing this??
Thanks for any help.
Walter
parent table, then another insert to a related or child table. both tables
are newly created and empty
The first insert works fine, but the second insert gives the following error
INSERT statement conflicted with COLUMN FOREIGN KEY constraint
'FK_ClientSW_Table_ClientTable'. The conflict occurred in database 'CGP',
table 'ClientTable', column 'id'. I
I made i diagram linking the two tables on
ClientTable.id ->ClientSW_Table.ClientId. Does that actually create the
entity relation?
but if I stop the app, and then attempt to do the second write again, using
the same code, it works.
Here is some of the relevant code:
Set cmd = CreateObject("Adodb.Command")
cmd.ActiveConnection = Application.CurrentProject.Connection
strCMD = "Insert into ClientTable(LastName,FirstName) values('" + sLastName
+ "','" + sFirstName + "')"
cmd.CommandText = strCMD
cmd.Execute , nrecs
'get the ClientId value for the newly added record
strSQL = "select max(ClientId) from tbl_CLIENTS"
Set RS = CreateObject("Adodb.RecordSet")
RS.Open strSQL, Application.CurrentProject.Connection, 1 ' 1 =
adOpenKeyset
NewClientRecId = RS(0)
RS.Close
Set RS = Nothing
strCMD = "Insert into ClientSW_Table(ClientId,SWid) VALUES(" +
Str(NewClientRecId) + "," + sSWID + ")"
cmd.CommandText = strCMD
cmd.Execute , nrecs 'This fails
How should I be doing this??
Thanks for any help.
Walter