trouble with SQL INSERT INTO

ckib

Board Regular
Joined
Sep 14, 2005
Messages
219
Here we go again ... does it ever end??? I'm trying to insert one record into table tblSegment (this is an intersection table). The fields are defined as follows:

seg_projectID is Text
seg_contactID is Long
seg_num is Integer

The primary key is a combination of seg_projectID and seg_contactID

my vars are defined:

Dim strProjectID As String
Dim lngContactID As Long

Here is the code:

' establish this new contact as a research participant
' populate tblSegment records (intersection table) for this contact

lngContactID = Me.contactID
strProjectID = Me.cont_projectID

strSQL = "INSERT INTO tblSegment (seg_projectID, seg_ContactID, seg_num) " & _
"VALUES ('" & strProjectID & "', " & lngContactID & ", " & intSegment & ");"

MsgBox "from CmdDuplicateContact strSQL = " & strSQL

' DoCmd.SetWarnings False
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings (True)

The strSQL string looks fine to me, but I get the error:

Microsoft can't append all the records in the append query.

.... it didn't add 1 record(s) to the table due to key violations ...

I can't figure out what the problem is as the values displayed in strSQL in the message box look fine! Both primary key fields are defined as indexed(duplicates ok).

Any help would be greatly appreciated!!! Thanks.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
key violation

Light bulb moment ... just figured out what the problem is ... I haven't created the record in tblContact yet. :eek:
 
Upvote 0

Forum statistics

Threads
1,215,352
Messages
6,124,457
Members
449,161
Latest member
NHOJ

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top