Question about Microsoft Visual Basic 6.0 for PC

1 Answer

Book mark property of recordset (ado)

Tell me the full code to understand the bookmark property of recordset as soon as possible


Posted by on

1 Answer

  • Level 1:

    An expert who has achieved level 1.

    MVP:

    An expert that got 5 achievements.

    Scholar:

    An expert who has written 20 answers of more than 400 characters.

    Hot-Shot:

    An expert who has answered 20 questions.

  • Contributor
  • 40 Answers

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

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

1 Answer

How to connect visual basic program book title to access without ado?


what exactly are you trying to do
you can use ado,ado.net or use the entire routine in programming

write like

dim con as connection
dim rec as new recordset

rec = con.open(<<<access provider library>>>,<<<mode>>>,<<<password if any>>>)

..
...
...

your logic
...
..
con.close

just search for access library

Feb 27, 2011 | Microsoft Mlf Visual Studio Enterprise...

1 Answer

Saving the info that i entered in my visual basic in microsoft access.. how to code the save???


check this out
Rst.Open "users", strConnect, , , adCmdTable With Rst .AddNew .Fields("username") = txtname.Text .Fields("User_Password") = txtpws.Text .Fields("Access_Type") = cmbUserTypes.Text .Fields("Date_Created") = Now .Update End With Rst.Close

'#### connection to databas
Public connConnection As New ADODB.Connection Public rsRecordSet As New ADODB.Recordset Public rsRecordSet1 As New ADODB.Recordset Public Rst As New ADODB.Recordset Public Rst1 As New ADODB.Recordset Public Rst2 As New ADODB.Recordset Public Rst3 As New ADODB.Recordset Public strConnect As String Public ConnectionOk As Boolean


Public Sub ConnectionMOd() Dim strProvider As String Dim strDataSource As String Dim strDataBaseName As String Dim i As Integer On Error GoTo ErrorTimer strProvider = "provider=Microsoft.Jet.OLEDB.4.0;" strDataSource = App.path ' strDataBaseName = "Z:\database.mdb" ' strDataSource = App.Path strDataBaseName = "\database.mdb" strDataSource = "Data Source= " & strDataSource & strDataBaseName strConnect = strProvider & strDataSource
Set connConnection = New ADODB.Connection connConnection.CursorLocation = adUseClient connConnection.Open strConnect
Set Rst = New ADODB.Recordset Rst.CursorType = adOpenStatic Rst.CursorLocation = adUseClient Rst.LockType = adLockOptimistic ' adLockOptimistic
Set Rst1 = New ADODB.Recordset Rst1.CursorType = adOpenStatic Rst1.CursorLocation = adUseClient Rst1.LockType = adLockOptimistic
Set Rst2 = New ADODB.Recordset Rst2.CursorType = adOpenStatic Rst2.CursorLocation = adUseClient Rst2.LockType = adLockOptimistic Set Rst3 = New ADODB.Recordset Rst3.CursorType = adOpenStatic Rst3.CursorLocation = adUseClient Rst3.LockType = adLockOptimistic ConnectionOk = True Exit Sub ErrorTimer: MsgBox "Error Connecting To DataBase Please Check Network path", vbCritical, "Connection Error" End End Sub

Jan 08, 2010 | Microsoft Visual Basic Enterprise Edition...

1 Answer

Example sorurce code for database


Hello my friend try this code: This code is design for Visual Basic 6.0
Function for Connection and recordset string.  '========Connection String====== Public Sub connection(ByRef dConnection As ADODB.connection, ByVal dLocation As String)     dConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dLocation & ";Persist Security Info=False;" End Sub '======End of Connection String======
'=======Recordset String=========== Public Sub recordset(ByRef sRecordset As ADODB.recordset, ByRef sConnection As ADODB.connection, ByVal sSQl As String) With sRecordset .CursorLocation = adUseClient .Open sSQl, sConnection, adOpenKeyset, adLockOptimistic End With End Sub '======End Recordset String========
How to apply the above function? Application:
'====== Command Save Button======== Private Sub cmdsave_Click() Dim cn3 As New ADODB.connection Dim rs3 As New ADODB.recordset
Call connection(cn3, App.Path & "\CASGC.mdb") Call recordset(rs3, cn3, "Select * from Debtor_Creditor_Account") Set dtglobal.DataSource = rs3.DataSource   
With rs3   .AddNew   .Fields("Code") = txtCode.Text   .Fields("Description") = txtDescription.Text   .Fields("Tag") = cbotag.Text   .Update   .Requery    End With   MsgBox "New Account has been Added", vbInformation   Set cn3 = Nothing Set rs3 = Nothing
End Sub '=======end of Command Save button=====
The advantage of using this code is setting your database connection is you have a reliable connection towards your database where ever you place your database you can you don't to remount you databse connection control. Also you are no longer need to use a ADO control or DAO control just copy the function and paste it in your coding area and call the function and you have now a working database and recordset connection string. 

For more details regarding how to apply this code just email me at this address: geo_jonas@yahoo.com to get more codes. thanks.. Please rate this Solution.

Jul 08, 2009 | Microsoft Visual Basic 6.0 for PC

2 Answers

Free visual basic source code salary database sample


you solution is her



Building Websites with VB.NET and DotNetNuke 4/by Daniel N. Egan (Author), Steve Valenzuela (Author), Michael Washington (Author)
Description
DotNetNuke is an open-source Content Management System and web application framework. DotNetNuke has taken the Microsoft world by storm and now at version 4, its community has grown to over 200,000 users. This book covers virtually everything you need to know to get your DotNetNuke website up and running. Concisely written and with clear explanations, this book is covers installation, administration, deployment, site creation and all of the basic built in DotNetNuke modules. For developers, chapters on the core architecture, skinning and custom modules, including coverage of the DAL+, give you the skills to customize and extend your site. The book starts off by giving you a deep understanding of working with basic DotNetNuke sites, guiding you through the features and giving you the confidence to create and manage your site. After that, you will journey to the heart of DotNetNuke, and learn about its core architecture. Always concise, relevant and practical, you will find out what makes DotNetNuke tick, and from there, you will be ready to customize DotNetNuke. Developers will enjoy the detailed walkthrough of creating a new custom modules. Special emphasis is given to the DAL+, an extended feature set of the DotNetNuke Data Access Layer (DAL). You will see how to create custom modules with the DAL+, and invigorate your module development. Web designers will enjoy the material on skinning, helping them to create a new look for their site. You will learn about creating new skins, and packaging them up for easy deployment. You will master all of this as you leap into the development of a DotNetNuke 4 site. This book will give you the skills to create and manage DotNetNuke websites as quickly as possible. You will:
* Install and configure DotNetNuke
* Master the standard modules
* Understand the core architecture of DotNetNuke
* Explore the inner workings of DotNetNuke modules
* Extend DotNetNuke using the DAL and DAL+ to create powerful custom modules
* Create your own skin using a HTML Editor
* Find out about where and how to host and deploy your site
You can use this book to help you set up and administer a DotNetNuke portal, even if you have a limited knowledge of ASP.NET. You will learn how to setup and administer an example site, stepping through all the tasks to ease your learning. If you are a developer, this book will help you extend the DotNetNuke portal by first helping you understand how the core framework works and then show you how to create custom modules and skins. A rudimentary knowledge of VB.NET programming is assumed, but the emphasis is not on becoming a better VB.NET programmer but on taming DotNetNuke. This book has been written for both the beginner wanting to set up a website and also ASP.NET developers with a grasp of VB.NET who want a deeper understanding of how to work with DotNetNuke. To work with the DotNetNuke code, you will need access to Visual Web Developer Express or Visual Studio .NET 2005. No prior knowledge of DotNetNuke is assumed.

download link:
http://w14.easy-share.com/1701584071.html
or:
http://dep

May 03, 2009 | Microsoft Visual Basic Enterprise Edition...

1 Answer

Convert mdb to text files with vb 6.0 code


You will need to open the file using ADO and read the data into a recordset. Then loop through the rows and write them to a text file and use concatenation to format the rows in the text file as needed (CSV, tab delimited, whatever you need). Remember to add a vbCrLf after each row!

Apr 10, 2009 | LEAD Technologies Compilers & Programming...

1 Answer

How to access data from ms access with buffer in class code with vb application


Use ADO and create a connection string for a Jet file (version matters here when creating the string). Then use ADO commands and return recordsets to buffer your data.

Mar 26, 2009 | Microsoft Visual Basic 6.0 for PC

1 Answer

I can't add data in the database using vb


Hi,
The database can be any like oracle.

Two type of connection u can make.
One of such connection is ADODB

The code is like

Dim ors As ADODB.Recordset
Dim oconn As Connection
Dim Qry as String
dim Qry1 as string
Set ors = New ADODB.Recordset
Set oconn = New ADODB.Connection
Chk_selectall.Visible = False

oconn.Open "Provider=MSDAORA.1;" & "user id = " & Username & _
";password = " & Password & ";data source = " & Conn_string _
& ";Persist Security Info=True"

Qry = "insert into table1 values (100,'we')"

oconn.execute "Qry"

If u select any data then u ve to use
Qry1 = "select * from table1"

ors.open "Qry1",oconn

do until ors.EOF

msgbox ors(0) & "," & ors(1)

ors.movenext;

loop

Mar 17, 2009 | Microsoft Visual Basic 6.0 for PC

1 Answer

About EOF and BOF


Hello Gugukandmiaw
You do not have to use the elseif statement. Maybe this will work.
Greetings Fred Roubos.


With frmPetugasView.Adodc1.Recordset
If frmPetugasView.Tag = "New" Then
.AddNew
!PetugasID = txtInput(0).Text
!NamaPetugas = txtInput(1).Text
!Keterangan = txtInput(2).Text
.Update
End if

If frmPetugasView.Tag = "Edit" Then
!PetugasID = txtInput(0).Text
!NamaPetugas = txtInput(1).Text
!Keterangan = txtInput(2).Text
.Update
End If
End With

Dec 18, 2008 | Compilers & Programming Tools

1 Answer

Vb 6.0 ado connection without ado control moving next record


I see 2 problems with your code.

1) Each time you call cmdnext_Click, you're reopening the database. Each time you do that, you start at the beginning of the file. You need to have the database opened once, somewhere else in your program. Be sure that the record set is visible from this sub.

2) In order to use the "Next" function, you need a loop like this

'test for no records
IF REC.BOF and REC.EOF then
msgbox "No Records Found"
exit sub
end if

IF NOT REC.EOF then
REC.MoveNext
(display your fields)
END IF


Again, this will only work if your database is opened outside of the cmdNext_Click routine.

Jul 08, 2008 | Microsoft Compilers & Programming Tools

1 Answer

Export data in excel sheet and in specific column


I did not write this but look towards the end of the code and it will give you an idea on how to do it

Sub ExportToExcel(strOutputFile As String, Optional boolSuppressMessages As Boolean = False)

Dim strTemplateFile As String
Dim fso As Scripting.FileSystemObject
Dim cnn As ADODB.Connection
Dim rstTarget As ADODB.Recordset
Dim rstCustomers As ADODB.Recordset
Dim rstServiceReps As ADODB.Recordset

On Error GoTo ErrorHandler: On Error GoTo 0

Set fso = New Scripting.FileSystemObject

' Get template file path
strTemplateFile = CurrentProject.path & "\CompaniesEmployeesList.xlt"

' Copy template to the target
fso.CopyFile strTemplateFile, strOutputFile, False

' Open a connection to the workbook
Set cnn = New ADODB.Connection
cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
cnn.ConnectionString = "Data Source=" & strOutputFile & ";" & _
"Extended Properties=""Excel 8.0"""
cnn.Mode = adModeReadWrite
cnn.Open

' Open the target recordset (the Excel sheet)
Set rstTarget = New ADODB.Recordset
rstTarget.Open "SELECT [ID], [Name], [City] " & _
"FROM [Sheet1$]", cnn, adOpenDynamic, adLockOptimistic

' Open Customer data recodset
Set rstCustomers = New ADODB.Recordset
rstCustomers.Open "SELECT CompanyID, CompanyName, City " & _
"FROM Customers " & _
"WHERE City = 'Madrid' " & _
"ORDER BY CompanyName", CurrentProject.Connection

' Open Service Rep data recodset
Set rstServiceReps = New ADODB.Recordset
rstServiceReps.Open "SELECT EmployeeID, [LastName] & "", "" & [FirstName] AS Name, City " & _
"FROM Employees " & _
"WHERE City = 'Madrid' " & _
"ORDER BY [LastName]", CurrentProject.Connection

' Loop through Customers result set and copy to target
Do While Not rstCustomers.EOF
rstTarget.AddNew
rstTarget![ID] = rstCustomers!CompanyID
rstTarget![Name] = rstCustomers!CompanyName
rstTarget![City] = rstCustomers!City
rstCustomers.MoveNext
Loop

' Insert blank line between result sets.
rstTarget.AddNew
rstTarget![ID] = ""
rstTarget![Name] = ""
rstTarget![City] = ""
rstTarget.Update

' Loop through Service Reps result set and copy to target
Do While Not rstServiceReps.EOF
rstTarget.AddNew
rstTarget![ID] = rstServiceReps!EmployeeID
rstTarget![Name] = rstServiceReps!Name
rstTarget![City] = rstServiceReps!City
rstTarget.Update
rstServiceReps.MoveNext
Loop

rstTarget.Close
rstCustomers.Close
rstServiceReps.Close

cnn.Close

If Not boolSuppressMessages Then
MsgBox "Workbook Created", vbInformation + vbOKOnly, "ExcelExport"
End If

ExitHere:
On Error Resume Next
Set rstTarget = Nothing
Set cnn = Nothing
Set rstCustomers = Nothing
Set rstServiceReps = Nothing
Exit Sub

ErrorHandler:
Eval "MsgBox(""Error " & Err.Number & "@" & Err.Description & "@"")"

On Error Resume Next

If Not cnn Is Nothing Then
cnn.Close
End If

Resume ExitHere

End Sub

Jan 03, 2008 | Compilers & Programming Tools

Not finding what you are looking for?
Microsoft Visual Basic 6.0 for PC Logo

296 people viewed this question

Ask a Question

Usually answered in minutes!

Top Microsoft Compilers & Programming Tools Experts

Fred Block
Fred Block

Level 2 Expert

289 Answers

Robin Hill
Robin Hill

Level 3 Expert

1251 Answers

Brian Sullivan
Brian Sullivan

Level 3 Expert

27725 Answers

Are you a Microsoft Compiler and Programming Tool Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...