Article ID: 195221
Article Last Modified on 3/14/2005
rsCustomers.Open strPath, , adOpenStatic, _
adLockBatchOptimistic, adCmdFile
Set rsCustomers.ActiveConnection = cnNWind
rsCustomers!CompanyName = InputBox("Enter new CompanyName")
rsCustomers.Update
rsCustomers.UpdateBatch
rsCustomers.Close
This code successfully updates the back-end database if the recordset's
ActiveConnection property is set to something other than cnNWind before
executing.
Set rsCustomers = New ADODB.Recordset
rsCustomers.Open strPath, cnNWind, adOpenStatic, _
adLockBatchOptimistic, adCmdFile
rsCustomers!CompanyName = InputBox("Enter new CompanyName")
rsCustomers.Update
rsCustomers.UpdateBatch
rsCustomers.Close
Private Sub Form_Load()
Dim cnNWind As ADODB.Connection
Dim rsCustomers As ADODB.Recordset
Dim strConn As String, strSQL As String, strPath As String
strConn = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
"Data Source=C:\VS98\VB98\NWind.MDB;"
strSQL = "SELECT CustomerID, CompanyName FROM Customers"
strPath = "C:\rsCustomers.adtg"
'Delete the file if it exists.
If Dir(strPath) <> "" Then
Kill strPath
End If
'Establish a connection to the Northwind database.
Set cnNWind = New ADODB.Connection
cnNWind.CursorLocation = adUseClient
cnNWind.Open strConn
'Query database for customer information.
'Save results to file.
Set rsCustomers = New ADODB.Recordset
rsCustomers.Open strSQL, cnNWind, adOpenStatic, _
adLockBatchOptimistic, adCmdText
MsgBox "Original CompanyName = " & rsCustomers!CompanyName
rsCustomers.Save strPath
rsCustomers.Close
'Open saved recordset, modify it and attempt to
'update the database.
rsCustomers.Open strPath, cnNWind, adOpenStatic, _
adLockBatchOptimistic, adCmdFile
rsCustomers!CompanyName = InputBox("Enter new CompanyName")
rsCustomers.Update
rsCustomers.UpdateBatch
rsCustomers.Close
'Query the database to see if it was successfully updated.
rsCustomers.Open strSQL, cnNWind, adOpenStatic, _
adLockReadOnly, adCmdText
MsgBox "CompanyName = " & rsCustomers!CompanyName
rsCustomers.Close
Set rsCustomers = Nothing
cnNWind.Close
Set cnNWind = Nothing
End Sub
'Open saved recordset, modify it and attempt to
'update the database.
rsCustomers.Open strPath, Nothing, adOpenStatic, _
adLockBatchOptimistic, adCmdFile
Set rsCustomers.ActiveConnection = cnNWind
rsCustomers!CompanyName = InputBox("Enter new CompanyName")
rsCustomers.Update
rsCustomers.UpdateBatch
rsCustomers.Close
Additional query words: kbdse kbSample
Keywords: kbbug kbfix kbmdac210sp2fix kbado210sp2fix kbmdacnosweep KB195221