getrows using dao

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • atksamy
    New Member
    • Oct 2008
    • 91

    getrows using dao

    In DAO connection
    Is it possible to get only the required field values into an array by using getrows
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    How to Retrieve Data From a DAO Recordset Using GetRows()

    Comment

    • atksamy
      New Member
      • Oct 2008
      • 91

      #3
      yes but using getrows in dao it wouldnt be possible to get the values of only one field right?

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        yes but using getrows in dao it wouldnt be possible to get the values of only one field right?
        Yes it is quite possible, and I modified the code to show you how it can be exactly done in a more self explanatory manner. Any further questions, feel free to ask.
        Code:
        Dim MyDB As DAO.Database
        Dim rstEmployees As DAO.Recordset
        Dim varEmployees As Variant
        Dim lngRecNumber As Long
        Dim lngNumOfRecords As Long
          
        'Make up of qryEmployees (5 Fields/9 Records) based on the
        'sample Northwind.mdb Database
          '[LastName] - Ascending
          '[FirstName] - Ascending
          '[Address]
          '[City]
          '[Region]
          
        Set MyDB = CurrentDb
        Set rstEmployees = MyDB.OpenRecordset("qryEmployees", dbOpenSnapshot)
          
        'Sometimes necessary for a valid Record Count
        rstEmployees.MoveLast
        rstEmployees.MoveFirst
        
        lngNumOfRecords = rstEmployees.RecordCount
        
        'Let's retrieve ALL Rows in the rstEmployees Recordset
        varEmployees = rstEmployees.GetRows(rstEmployees.RecordCount)
        
        'All Data is now contained within the 2-Dimensional Variant Array varEmployees.
        'The 1st Element of the Array is the Field, in this case it is the 3rd Field (2),
        '(Indexed at 0), representing the Address. The 2nd Element is the Row which is
        'incremented within the For...Next Loop to retrieve all Values in the 3rd Field
        '[Address] contained in varEmployees
        
        For lngRecNumber = 0 To lngNumOfRecords - 1
          Debug.Print varEmployees(2, lngRecNumber)
        Next

        Comment

        Working...