chobo321321
Registered User.
- Local time
- Today, 08:36
- Joined
- Dec 19, 2004
- Messages
- 53
Hi, I am having some weird problems when using bookmarks. All I want to do is display 1 record at a time in a listbox each time a user clicks a button.
At the moment I save the bookmark value to a global variable, and when the user makes another click is should move to that record. Right now it gives me a "Not a valid Bookmark" error when I click on the button for the second time. First time is alright, but second time it comes up with that error. Any help is appreciated.
Here's an example of my code
At the moment I save the bookmark value to a global variable, and when the user makes another click is should move to that record. Right now it gives me a "Not a valid Bookmark" error when I click on the button for the second time. First time is alright, but second time it comes up with that error. Any help is appreciated.
Here's an example of my code
Code:
Option Compare Database
Dim varbookmark As Variant
Private Sub cmdadd_Click()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Set cnn = CurrentProject.Connection
strSQL = "SELECT * " & _
"FROM tblHotel"
rst.Open strSQL, cnn, adOpenStatic
With lstHotel
.ColumnCount = 4
.ColumnWidths = "1in;"
End With
Do While rst.EOF <> True
If varbookmark = "" Then
lstHotel.AddItem rst!Name
rst.MoveNext
varbookmark = rst.Bookmark
Exit Sub
Else
rst.Bookmark = varbookmark
lstHotel.AddItem rst!Name
rst.MoveNext
varbookmark = rst.Bookmark
Exit Sub
End If
Loop
End Sub