Dynamic-Type Recordset Example

This example opens a dynamic-type Recordset object and enumerates its records.

Sub dbOpenDynamicX()

   Dim wrkMain As Workspace
   Dim conMain As Connection
   Dim qdfTemp As QueryDef
   Dim rstTemp As Recordset
   Dim strSQL As String
   Dim intLoop As Integer

   ' Create ODBC workspace and open connection to
   ' SQL Server database.
   Set wrkMain = CreateWorkspace("ODBCWorkspace", _
      "admin", "", dbUseODBC)
   Set conMain = wrkMain.OpenConnection("Publishers", _
      dbDriverNoPrompt, False, _
      "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")
   ' Open dynamic-type recordset.
   Set rstTemp = _
      conMain.OpenRecordset("authors", _
      dbOpenDynamic)

   With rstTemp
      Debug.Print "Dynamic-type recordset: " & .Name

      ' Enumerate records.
      Do While Not .EOF
         Debug.Print "    " & !au_lname & ", " & _
            !au_fname
         .MoveNext
      Loop

      .Close
   End With

   conMain.Close
   wrkMain.Close

End Sub