Article ID: 190369
Article Last Modified on 11/3/2003
Private Sub Command1_Click()
Dim Conn As New rdoConnection
Dim CSt As String
Dim rs As rdoResultset
Dim sSQL As String
Dim i As Long
With Conn
.CursorDriver = rdUseServer
.Connect = "DRIVER={sql server};SERVER=yourserverhere;" & _
"DATABASE=pubs;UID=UserName;PWD=StrongPassword"
.EstablishConnection
End With
sSQL = "SELECT * FROM titles where pub_id = '0877'"
Set rs = Conn.OpenResultset(Name:=sSQL, Type:=rdOpenKeyset, _
LockType:=rdConcurRowVer, Options:=rdExecDirect)
Conn.BeginTrans
' If the resultset was at EOF before the AddNew and Update,
' LastModified will be the bookmark of the first item in
' the resultset. For instance, the following pubdates will
' be the same. If the resultset is not at EOF, the first
' pubdate will be the date of the newly added row.
rs.MoveLast '<<- These lines cause
rs.MoveNext '<<- the problem.
Debug.Print rs.EOF
With rs
.AddNew
rs("pub_id") = "0877"
rs("title_id") = "MC7769"
rs("title") = "Test Title"
rs("type") = "business"
rs("price") = 2.99
rs("advance") = 5000
rs("pubdate") = "01/01/98"
.Update
If .Bookmarkable Then
.Bookmark = .LastModified
'The following prints the pubdate of the
'first record in the resultset.
Debug.Print "Pub date (last modified)= " _
& rs("title_id")
Debug.Print "Bookmark = " & .Bookmark
'If you do a MoveLast here, you can get
'to the newly added record.
.MoveLast
Debug.Print "Pub date (move last) = " _
& rs("title_id")
Debug.Print "Bookmark = " & .Bookmark
'The following produces the same as
'the LastModified bookmark.
.MoveFirst
Debug.Print "Pub date = (move first) " _
& rs("title_id")
Debug.Print "Bookmark = " & .Bookmark
End If
End With
Conn.RollbackTrans
End Sub
Keywords: kbbug kbpending kbcode KB190369