In DAO connection
Is it possible to get only the required field values into an array by using getrows
Is it possible to get only the required field values into an array by using getrows
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