Microsoft Access
  Home arrow Microsoft Access arrow Page 3 - Cursors in MS Access and ADO
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MICROSOFT ACCESS

Cursors in MS Access and ADO
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 9
    2006-05-03

    Table of Contents:
  • Cursors in MS Access and ADO
  • ADO Cursors
  • The Recordset's RecordCount, AbsolutePosition, BOF and EOF properties
  • CursorType changed to adOpenForwardOnly

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Cursors in MS Access and ADO - The Recordset's RecordCount, AbsolutePosition, BOF and EOF properties


    (Page 3 of 4 )

    In order to explore the properties of the recordset, the RecordCount, AbsolutePosition, BOF, and EOF, the code shown may be used to visualize what these properties mean as related to a recordset. In the code presented, the cursor type property is set to adOpenStatic which means you can go forward (use commands like MoveNext) and backward (use commands like Move Previous).

    The picture shown next depicts the relative positions of some of the properties. The data can be viewed in a forward or backward direction. When the recordset opens, its Absolute position is 1 as shown. If you go backward you will get into the BOF area. Similarly if you go to the last record and try to go the next position you will be in the EOF area. The BOF and EOF properties give you the hooks to determine whether you have strayed into these areas. The RecordCount property shows you how many records there are in the query result.

    What is achieved in the code is opening a recordset with a cursor that supports the bidirectional movement, in this example, adOpenStatic. After opening the recordset the AbsolutePosition, BOF and EOF properties of the recordset are evaluated as the recordset is moved to different locations using MovePrevious, MoveNext, and MoveLast properties of the recordset. The results are gathered in a string and dumped to a textbox as shown in the picture. The AbsolutePosition when the BOF is true, and when EOF is true are negative numbers. It does not mean they jumped to these values. They actually represent enumerated constants adPosBOF and adPosEof. These are not frequently used.

    Option Compare Database
    Private conn As ADODB.Connection
    Private strsql As String
    Private rst3 As ADODB.Recordset
    Private Sub Form_Load()
    Dim strg As String
    strsql = "Select EmployeeID, LastName, FirstName, City from Employees"
    strg = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Program Files
    Microsoft OfficeOFFICE11SAMPLESNorthwind.mdb;Persist Security Info=

    False" 'CursorType=3 adOpenStatic Set conn = New ADODB.Connection Set rst3 = New ADODB.Recordset conn.Open strg Set rst3.ActiveConnection = conn rst3.CursorType = 3 rst3.Open strsql, strg 'MsgBox (rst.CursorType) Dim strgs As String strgs = "" strgs = strgs + "Cursor adOpenStatic" & vbCrLf strgs = strgs + "Number of rows (RecordCount) is: " & rst3.RecordCount &
    vbCrLf strgs = strgs + "Number of columns(Fields) is: " & rst3.Fields.Count &
    vbCrLf strgs = strgs + "----------------------------------------------------" &
    vbCrLf strgs = strgs + "This is the starting position of the recordset" & vbCrLf strgs = strgs + "----------------------------------------------------" &
    vbCrLf strgs = strgs + "Is it beginning of file(BOF) : " & rst3.BOF & vbCrLf strgs = strgs + "Is it end of file(EOF) : " & rst3.EOF & vbCrLf strgs = strgs + "What is the absolute position of record? : " &
    rst3.AbsolutePosition & vbCrLf ' ' ' strgs = strgs + "-----------------------------------------------------" &
    vbCrLf strgs = strgs + "MOVE the Recordset to its PREVIOUS position" & vbCrLf strgs = strgs + "-----------------------------------------------------" &
    vbCrLf rst3.MovePrevious strgs = strgs + "Is it beginning of file(BOF) : " & rst3.BOF & vbCrLf strgs = strgs + "Is it end of file(EOF) : " & rst3.EOF & vbCrLf strgs = strgs + "What is the absolute position of record? : " &
    rst3.AbsolutePosition & vbCrLf ' 'Move to the last position and find BOF, EOF, and AbsolutePosition ' strgs = strgs + "-----------------------------------------------------" &
    vbCrLf strgs = strgs + "MOVE the Recordset to its LAST position" & vbCrLf strgs = strgs + "-----------------------------------------------------" &
    vbCrLf rst3.MoveLast strgs = strgs + "Is it beginning of file(BOF) : " & rst3.BOF & vbCrLf strgs = strgs + "Is it end of file(EOF) : " & rst3.EOF & vbCrLf strgs = strgs + "What is the absolute position of record? : " &
    rst3.AbsolutePosition & vbCrLf ' 'Move next to last position and find BOF, EOF, and absolute Position ' strgs = strgs + "-----------------------------------------------------" &
    vbCrLf strgs = strgs + "Now MOVE the recordset to the NEXT position" & vbCrLf strgs = strgs + "-----------------------------------------------------" &
    vbCrLf rst3.MoveNext strgs = strgs + "Is it beginning of file(BOF) : " & rst3.BOF & vbCrLf strgs = strgs + "Is it end of file(EOF) : " & rst3.EOF & vbCrLf strgs = strgs + "What is the absolute position of record? : " &
    rst3.AbsolutePosition & vbCrLf ' Text0.SetFocus Text0.Text = strgs Set rst3 = Nothing Set conn = Nothing End Sub

    More Microsoft Access Articles
    More By Jayaram Krishnaswamy


       · The tutorial is written targeting the beginner and so the discussion is at its very...
       · These are excellent articles and I am enjoying reading them. We all have to start...
     

    MICROSOFT ACCESS ARTICLES

    - Linking SQL Express 2005 Tables to MS Access...
    - Working with Access Projects in Access 2007
    - Exploring Access 2007
    - Working with Stored Procedures in an MS Acce...
    - Creating and Using Action Queries
    - Creating Data Access Pages with Charts using...
    - Advanced Ideas using VBA
    - VBA Details
    - Updating Records in MS Access
    - Using ADO`s Record Object with URLs
    - Exporting XML from MS Access 2003
    - Importing XML into MS Access 2003
    - On Using Pass-through Queries in MS Access
    - Distributed Queries in MS Access
    - Configuring a Linked Microsoft Access Server...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT