This example demonstrates using the Resync method to refresh data in a static recordset.
'BeginResyncVB
'To integrate this code
'replace the data source and initial catalog values
'in the connection strings
Public Sub ResyncX()
'connection and recordset variables
Dim Cnxn As ADODB.Connection
Dim rstTitles As ADODB.Recordset
Dim strCnxn As String
Dim strSQLTitles As String
' Open connection
Set Cnxn = New ADODB.Connection
strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=Pubs;User Id=sa;Password=; "
Cnxn.Open strCnxn
' Open recordset using object refs to set properties
' that allow for updates to the database
Set rstTitles = New ADODB.Recordset
Set rstTitles.ActiveConnection = Cnxn
rstTitles.CursorType = adOpenKeyset
rstTitles.LockType = adLockOptimistic
strSQLTitles = "titles"
rstTitles.Open strSQLTitles
'rstTitles.Open strSQLTitles, Cnxn, adOpenKeyset, adLockPessimistic, adCmdTable
'the above line of code passes the same refs as the object refs listed above
' Change the type of the first title in the recordset
rstTitles!Type = "database"
' Display the results of the change
MsgBox "Before resync: " & vbCr & vbCr & _
"Title - " & rstTitles!Title & vbCr & _
"Type - " & rstTitles!Type
' Resync with database and redisplay results
rstTitles.Resync
MsgBox "After resync: " & vbCr & vbCr & _
"Title - " & rstTitles!Title & vbCr & _
"Type - " & rstTitles!Type
rstTitles.CancelBatch
rstTitles.Close
End Sub
'EndResyncVB
Recordset Object | Resync Method
© 1998-2001 Microsoft Corporation. All rights reserved.