#$>ATAbsolutePage, PageCount, and PageSize Properties Example

 

This example uses the AbsolutePage, PageCount, and PageSize properties to display names and hire dates from the Employee table five records at a time.

Public Sub AbsolutePageX()

  

   Dim rstEmployees As ADODB.Recordset

   Dim strCnn As String

   Dim strMessage As String

   Dim intPage As Integer

   Dim intPageCount As Integer

   Dim intRecord As Integer

 

   ' Open a recordset using a client cursor

   ' for the employee table.

   strCnn = "driver={SQL Server};server=srv;" & _

      "uid=sa;pwd=;database=pubs"

   Set rstEmployees = New ADODB.Recordset

   ' Use client cursor to enable AbsolutePosition property.

   rstEmployees.CursorLocation = adUseClient

   rstEmployees.Open "employee", strCnn, , , adCmdTable

  

   ' Display names and hire dates, five records

   ' at a time.

   rstEmployees.PageSize = 5

   intPageCount = rstEmployees.PageCount

   For intPage = 1 To intPageCount

      rstEmployees.AbsolutePage = intPage

      strMessage = ""

      For intRecord = 1 To rstEmployees.PageSize

         strMessage = strMessage & _

            rstEmployees!fname & " " & _

            rstEmployees!lname & " " & _

            rstEmployees!hire_date & vbCr

         rstEmployees.MoveNext

         If rstEmployees.EOF Then Exit For

      Next intRecord

      MsgBox strMessage

   Next intPage

   rstEmployees.Close

 

End Sub


#$>ATAbsolutePosition and CursorLocation Properties Example

 

This example demonstrates how the AbsolutePosition property can track the progress of a loop that enumerates all the records of a Recordset. It uses the CursorLocation property to enable the AbsolutePosition property by setting the cursor to a client cursor.

Public Sub AbsolutePositionX()

 

   Dim rstEmployees As ADODB.Recordset

   Dim strCnn As String

   Dim strMessage As String

 

   ' Open a recordset for the Employee table

   ' using a client cursor.

   strCnn = "driver={SQL Server};server=srv;" & _

      "uid=sa;pwd=;database=pubs"

   Set rstEmployees = New ADODB.Recordset

   ' Use client cursor to enable AbsolutePosition property.

   rstEmployees.CursorLocation = adUseClient

   rstEmployees.Open "employee", strCnn, , , adCmdTable

  

   ' Enumerate Recordset.

   Do While Not rstEmployees.EOF

      ' Display current record information.

      strMessage = "Employee: " & rstEmployees!lName & vbCr & _

         "(record " & rstEmployees.AbsolutePosition & _

         " of " & rstEmployees.RecordCount & ")"

      If MsgBox(strMessage, vbOKCancel) = vbCancel _

         Then Exit Do

      rstEmployees.MoveNext

   Loop

 

   rstEmployees.Close

 

End Sub


#$>ATActiveConnection, CommandText, CommandTimeout, CommandType, Size, and Direction Properties Example

 

This example uses the ActiveConnection, CommandText, CommandTimeout, CommandType, Size, and Direction properties to execute a stored procedure.

Public Sub ActiveConnectionX()

 

   Dim cnn1 As ADODB.Connection

   Dim cmdByRoyalty As ADODB.Command

   Dim prmByRoyalty As ADODB.Parameter

   Dim rstByRoyalty As ADODB.Recordset

   Dim rstAuthors As ADODB.Recordset

   Dim intRoyalty As Integer

   Dim strAuthorID As String

   Dim strCnn As String

 

   ' Define a command object for a stored procedure.

   Set cnn1 = New ADODB.Connection

   strCnn = "driver={SQL Server};server=srv;" & _

      "uid=sa;pwd=;database=pubs"

   cnn1.Open strCnn

   Set cmdByRoyalty = New ADODB.Command

   Set cmdByRoyalty.ActiveConnection = cnn1

   cmdByRoyalty.CommandText = "byroyalty"