
Problem in adding record in an ODBC-connected Access database
Hi all experts,
I have a problem in adding record into an Access database connected by
ODBC. My code is as that of end of this mail. Everything work OK but
error happen when the program reach the last line (i.e. ".Update"). The
error is "ODBC call failed" (3146).
From the help, it says it is because an ODBC connect is lost due to,
say, not logging-in to a network. However, the data source is an Access
database in my local hard drive and data retrieving is 100% correct.
I'm wondering what is wrong with these few lines of code.
Please help! Thank you!
William
Sub AddNewRecord()
Dim dbsContent As Database
Dim wrkODBC As Workspace
Dim rstTmp As Recordset
Set wrkODBC = CreateWorkspace("", "", "", dbUseODBC)
Set dbsContent = wrkODBC.OpenDatabase("resource-db",
dbDriverNoPrompt,
False,"ODBC;DATABASE=resource-db;UID=;PWD=;DSN=resources")
Set rstTmp = dbsContent.OpenRecordset("CUSTOMER", dbOpenDynaset,
dbExecDirect, dbOptimisticValue)
With rstTmp
.AddNew
!CUST_ID = 1
!CUST_NAME = "Peter"
.Update <------------ Problem in this line
End With
End Sub