Question about Microsoft Visual Basic 6.0 for PC
Tell me the full code to understand the bookmark property of recordset as soon as possible
The bookmark property of a recordset lets you store and retrieve the location of a record in a variable so that you can move directly to it in your recordset without having to use a query to extract that record. Like you can just move forward a record and back a record, or move to the first or last records without a quesry statement, you can move to the bookmarked record directly in code.
Here's a good VB example that compares the bookmakr property to the movefirst and movelast properties. This should answer your question, and please rate my answer.
'BeginBOFVB 'To integrate this code 'replace the data source and initial catalog values 'in the connection string Public Sub Main() On Error GoTo ErrorHandler 'recordset and connection variables Dim Cnxn As ADODB.Connection Dim rstPublishers As ADODB.Recordset Dim strCnxn As String Dim strSQLPubs As String 'record variables Dim strMessage As String Dim intCommand As Integer Dim varBookmark As Variant ' open connection Set Cnxn = New ADODB.Connection strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _ "Initial Catalog='Pubs';Integrated Security='SSPI';" Cnxn.Open strCnxn ' Open recordset and use client cursor ' to enable AbsolutePosition property Set rstPublishers = New ADODB.Recordset strSQLPubs = "SELECT pub_id, pub_name FROM publishers ORDER BY pub_name" rstPublishers.Open strSQLPubs, strCnxn, adUseClient, adOpenStatic, adCmdText rstPublishers.MoveFirst Do Until rstPublishers.EOF ' Display information about current record ' and get user input strMessage = "Publisher: " & rstPublishers!pub_name & _ vbCr & "(record " & rstPublishers.AbsolutePosition & _ " of " & rstPublishers.RecordCount & ")" & vbCr & vbCr & _ "Enter command:" & vbCr & _ "[1 - next / 2 - previous /" & vbCr & _ "3 - set bookmark / 4 - go to bookmark]" intCommand = Val(InputBox(strMessage)) ' Check user input Select Case intCommand Case 1 ' Move forward trapping for EOF rstPublishers.MoveNext If rstPublishers.EOF Then MsgBox "Moving past the last record." & _ vbCr & "Try again." rstPublishers.MoveLast End If Case 2 ' Move backward trapping for BOF rstPublishers.MovePrevious If rstPublishers.BOF Then MsgBox "Moving past the first record." & _ vbCr & "Try again." rstPublishers.MoveFirst End If Case 3 ' Store the bookmark of the current record varBookmark = rstPublishers.Bookmark Case 4 ' Go to the record indicated by the stored bookmark If IsEmpty(varBookmark) Then MsgBox "No Bookmark set!" Else rstPublishers.Bookmark = varBookmark End If Case Else Exit Do End Select Loop ' clean up rstPublishers.Close Cnxn.Close Set rstPublishers = Nothing Set Cnxn = Nothing Exit Sub ErrorHandler: ' clean up If Not rstPublishers Is Nothing Then If rstPublishers.State = adStateOpen Then rstPublishers.Close End If Set rstPublishers = Nothing If Not Cnxn Is Nothing Then If Cnxn.State = adStateOpen Then Cnxn.Close End If Set Cnxn = Nothing If Err <> 0 Then MsgBox Err.Source & "-->" & Err.Description, , "Error" End If End Sub 'EndBOFVB
Posted on Jan 08, 2009
a 6ya expert can help you resolve that issue over the phone in a minute or two.
Best thing about this new service is that you are never placed on hold and get to talk to real repairmen in the US.
the service is completely free and covers almost anything you can think of.(from cars to computers, handyman, and even drones)
click here to download the app (for users in the US for now) and get all the help you need.
Posted on Jan 02, 2017
Tips for a great answer:
Jan 11, 2014 | Computers & Internet
Mar 03, 2011 | Google Chrome
Feb 27, 2011 | Microsoft Mlf Visual Studio Enterprise...
Jul 08, 2009 | Microsoft Visual Basic 6.0 for PC
May 16, 2009 | Microsoft Windows Vista Ultimate Edition
Apr 10, 2009 | LEAD Technologies Computers & Internet
Mar 26, 2009 | Microsoft Visual Basic 6.0 for PC
Feb 26, 2009 | Computers & Internet
Jul 20, 2008 | Microsoft Windows XP Professional
Jul 08, 2008 | Microsoft Computers & Internet
298 people viewed this question
Usually answered in minutes!
Step 2: Please assign your manual to a product: