accessNator
Registered User.
- Local time
- Today, 12:20
- Joined
- Oct 17, 2008
- Messages
- 132
I have a linked table that comes from SQL Server. This table has a PK defined, Identity is True and Identity Increment is 1
It checks to see if a record exists, if it doesnt it suppose to insert a new record into my table.
The 4 columns in my table in SQL Server are
CTCC_RefIID (Primary Key, integer, not null)
FK_KCN_REFID (FK, integer, not null)
FK_TOC_REFID (FK, integer, not null)
LastModifiedDateTime (datetime,null)
There are no Referential Integrity set too.
When it attempts to INSERT, it gets hung up and eventually I get the error message:
ODBC--Insert on a linked table 'CompanyToCarrierCode' failed.
My code looks like this:
It checks to see if a record exists, if it doesnt it suppose to insert a new record into my table.
The 4 columns in my table in SQL Server are
CTCC_RefIID (Primary Key, integer, not null)
FK_KCN_REFID (FK, integer, not null)
FK_TOC_REFID (FK, integer, not null)
LastModifiedDateTime (datetime,null)
There are no Referential Integrity set too.
When it attempts to INSERT, it gets hung up and eventually I get the error message:
ODBC--Insert on a linked table 'CompanyToCarrierCode' failed.
My code looks like this:
Code:
Private Sub Update_RemoteDatabase()
Dim sqlstr1 as String
Dim Table1 as String
Dim db As DAO.Database
Dim rstCarrierCode As DAO.Recordset
Dim getCompanyRefID As Long
getCompanyRefID = Forms!frmWorkSheetInput_Contributer!cboQuickSearch.Column(0)
Set db = CurrentDb 'Current Database
'============= Update OK_CompanyToCarrierCode Table
' Set Company Carrier Code
Table1 = "dbo_OK_CompanyToCarrierCode"
sqlstr1 = "SELECT * FROM " & Table1 & " WHERE FK_KCN_RefID =" & getCompanyRefID
Set rstCarrierCode = db.OpenRecordset(sqlstr1, dbOpenDynaset, dbSeeChanges)
With rstCarrierCode
If Not rstCarrierCode.EOF Then
'Begin Edit
.Edit
'Changes
!FK_TOC_RefId = Me.cmboCompanyCarrierType
!LastModifiedDateTime = Now()
.Update
Else
.AddNew
'New
!FK_KCN_RefId = getCompanyRefID
!FK_TOC_RefId = Me.cmboCompanyCarrierType
!LastModifiedDateTime = Now()
.Update
End If
End With
rstCarrierCode.Close
Set rstCarrierCode = Nothing
'============= END Update OK_CompanyToCarrierCode Table
Set db = Nothing
End Sub