Article ID: 161252
Article Last Modified on 1/19/2007
Set recordset=object.OpenRecordset(source, type, options, lockedits)You create an editable recordset when you use one of the following constants in the LockEdits argument of the OpenRecordset method:
dbOptimistic, dbPessimistic, dbOptimisticValue, or dbOptimisticBatchFor example, the following sample code fragment opens an editable recordset that uses optimistic record locking:
Set RS = conPubs.OpenRecordset("Authors",dbOpenDynamic,0,dbOptimistic)
NOTE: You must supply a zero (0) for the Options argument.
Sub ConnectAndAddRecords(UID as String, DSN as String, _
Optional PWD as String)
Dim wrkODBC As Workspace
Dim conPubs As Connection
Dim rstTmp As Recordset
' Create an ODBCDirect workspace.
Set wrkODBC = CreateWorkspace _
("NewODBCWorkspace", "admin", "", dbUseODBC)
' Open a connection to an ODBC data source.
Set conPubs = wrkODBC.OpenConnection("Connection1", _
dbDriverNoPrompt,,"ODBC;DATABASE=pubs;UID=" & UID _
& ";PWD=" & PWD & ";DSN=" & DSN)
' Open a recordset which is read-only by default.
Set rstTmp = conPubs.OpenRecordset("Authors", dbOpenDynamic)
rstTmp.AddNew
rstTmp!au_id = "111-11-1111"
rstTmp!au_lname = "Dickens"
rstTmp!au_fname = "Charles"
rstTmp!Contract = 0
rstTmp.Update
rstTmp.Close
conPubs.Close
wrkODBC.Close
End Sub
ConnectAndAddRecords "TestUser","TestDataSource","TestPwd"
Note that the code fails on the rstTmp.AddNew line with the following
error message:
169276 ACC97: OpenRecordset Method Options Incorrect for ODBCDirect
Additional query words: prb run time Error 3027 can t
Keywords: kberrmsg kbprb kbusage KB161252