Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sConnect As String
sConnect = "Provider=SQLOLEDB;Data source=MyServer;Database=Pubs;UID=<User ID>;PWD=<Strong Password>;"
cn.Open sConnect
cn.Execute "If Exists (Select * From sysobjects Where id = object_id('T1')) Drop Table T1"
cn.Execute "CREATE TABLE T1(K1 INT PRIMARY KEY, F1 VARCHAR(1) )"
cn.Execute "INSERT INTO T1 VALUES( 1, 'A')"
cn.Execute "INSERT INTO T1 VALUES( 2, 'B')"
cn.Execute "INSERT INTO T1 VALUES( 3, 'D')"
cn.Execute "INSERT INTO T1 VALUES( 4, 'E')"
rs.CursorLocation = adUseClient
rs.Open "Select * From T1", cn, adOpenKeyset, adLockBatchOptimistic
rs.MoveFirst 'Positions on 1, 'A'
rs.Sort = "F1" 'Still at 1, 'A'
rs!F1 = "C" 'Repositions between 2, 'B' and 3, 'D'
Debug.Print rs!K1, rs!F1 '1, 'C'
rs.MoveNext 'Now at 3, 'D'
Debug.Print rs!K1, rs!F1 '3, 'D'
rs!F1 = "F" 'Repositions after 4, 'E'
Debug.Print rs!K1, rs!F1 '3, 'F'
rs.MoveNext 'Repositions after the last record
Debug.Print rs.EOF