L
LisaB
When I run the following code I get an -- Error # 3146 ODBC Call Failed--
can anyone please tell me what is wrong and how to fix it
1. This is an Access 2000 application connected to a SQL2000 database
2. tblGrants is in the SQL2000 database
3. tblUploadGrants is an Access table (in the Front-end)
4. When debugging the error stops on -- .Update --
5. A new record never get added to the SQL table because of this error
6. In tblGrants there is an AutoNum field and field GRANTID is the Primary
Key
--------------------------
Public Sub AddUploadGrantRecords()
Dim UniqueNumber As Integer
Dim DestinationRS As DAO.Recordset
SQLStatement = "SELECT Max(tblGrants.AutoNum) AS MaxOfAutoNum FROM
tblGrants;"
Set TheDB = CurrentDb
Set SourceRS = TheDB.OpenRecordset(SQLStatement, dbOpenDynaset,
dbSeeChanges)
Set SourceRS2 = TheDB.OpenRecordset("tblUploadGrants", dbOpenDynaset,
dbSeeChanges)
Set DestinationRS = TheDB.OpenRecordset("tblGrants", dbOpenDynaset,
dbSeeChanges)
With SourceRS
UniqueNumber = !MaxOfAutonum + 1
End With
SourceRS.Close
If SourceRS2.RecordCount Then
SourceRS2.MoveFirst
Do Until SourceRS2.EOF
With DestinationRS
'.MoveLast
.AddNew 'adding to tblGrants
!GrantID = "CSAT" & UniqueNumber
!OrgID = SourceRS2![OrgID]
!GrantNum = SourceRS2![Grant No ]
!GranteeName = SourceRS2![Grantee ]
!Project = SourceRS2![Project ]
!StartDate = SourceRS2![Project Start ]
!EndDate = SourceRS2![Project End ]
!Deactivating = SourceRS2![Deactivating Date ]
!ProgramArea = SourceRS2![Program ]
!GFAProgram = SourceRS2![GFA Program ]
!Setting = SourceRS2![Setting ]
!Modality = SourceRS2![Modality ]
!SubPop = SourceRS2![Sub-Population ]
!Division = SourceRS2![Division ]
!Editor = "Upload - " & CurrentUser
!EditDate = Now()
.Update
End With
SourceRS2.MoveNext
UniqueNumber = UniqueNumber + 1
Loop
End If
SourceRS2.Close
DestinationRS.Close
End Sub
can anyone please tell me what is wrong and how to fix it
1. This is an Access 2000 application connected to a SQL2000 database
2. tblGrants is in the SQL2000 database
3. tblUploadGrants is an Access table (in the Front-end)
4. When debugging the error stops on -- .Update --
5. A new record never get added to the SQL table because of this error
6. In tblGrants there is an AutoNum field and field GRANTID is the Primary
Key
--------------------------
Public Sub AddUploadGrantRecords()
Dim UniqueNumber As Integer
Dim DestinationRS As DAO.Recordset
SQLStatement = "SELECT Max(tblGrants.AutoNum) AS MaxOfAutoNum FROM
tblGrants;"
Set TheDB = CurrentDb
Set SourceRS = TheDB.OpenRecordset(SQLStatement, dbOpenDynaset,
dbSeeChanges)
Set SourceRS2 = TheDB.OpenRecordset("tblUploadGrants", dbOpenDynaset,
dbSeeChanges)
Set DestinationRS = TheDB.OpenRecordset("tblGrants", dbOpenDynaset,
dbSeeChanges)
With SourceRS
UniqueNumber = !MaxOfAutonum + 1
End With
SourceRS.Close
If SourceRS2.RecordCount Then
SourceRS2.MoveFirst
Do Until SourceRS2.EOF
With DestinationRS
'.MoveLast
.AddNew 'adding to tblGrants
!GrantID = "CSAT" & UniqueNumber
!OrgID = SourceRS2![OrgID]
!GrantNum = SourceRS2![Grant No ]
!GranteeName = SourceRS2![Grantee ]
!Project = SourceRS2![Project ]
!StartDate = SourceRS2![Project Start ]
!EndDate = SourceRS2![Project End ]
!Deactivating = SourceRS2![Deactivating Date ]
!ProgramArea = SourceRS2![Program ]
!GFAProgram = SourceRS2![GFA Program ]
!Setting = SourceRS2![Setting ]
!Modality = SourceRS2![Modality ]
!SubPop = SourceRS2![Sub-Population ]
!Division = SourceRS2![Division ]
!Editor = "Upload - " & CurrentUser
!EditDate = Now()
.Update
End With
SourceRS2.MoveNext
UniqueNumber = UniqueNumber + 1
Loop
End If
SourceRS2.Close
DestinationRS.Close
End Sub