By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,506 Members | 2,275 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,506 IT Pros & Developers. It's quick & easy.

getrows using dao

atksamy
P: 91
In DAO connection
Is it possible to get only the required field values into an array by using getrows
Nov 5 '08 #1
Share this Question
Share on Google+
3 Replies


atksamy
P: 91
yes but using getrows in dao it wouldnt be possible to get the values of only one field right?
Nov 6 '08 #3

ADezii
Expert 5K+
P: 8,599
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.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rstEmployees As DAO.Recordset
  3. Dim varEmployees As Variant
  4. Dim lngRecNumber As Long
  5. Dim lngNumOfRecords As Long
  6.  
  7. 'Make up of qryEmployees (5 Fields/9 Records) based on the
  8. 'sample Northwind.mdb Database
  9.   '[LastName] - Ascending
  10.   '[FirstName] - Ascending
  11.   '[Address]
  12.   '[City]
  13.   '[Region]
  14.  
  15. Set MyDB = CurrentDb
  16. Set rstEmployees = MyDB.OpenRecordset("qryEmployees", dbOpenSnapshot)
  17.  
  18. 'Sometimes necessary for a valid Record Count
  19. rstEmployees.MoveLast
  20. rstEmployees.MoveFirst
  21.  
  22. lngNumOfRecords = rstEmployees.RecordCount
  23.  
  24. 'Let's retrieve ALL Rows in the rstEmployees Recordset
  25. varEmployees = rstEmployees.GetRows(rstEmployees.RecordCount)
  26.  
  27. 'All Data is now contained within the 2-Dimensional Variant Array varEmployees.
  28. 'The 1st Element of the Array is the Field, in this case it is the 3rd Field (2),
  29. '(Indexed at 0), representing the Address. The 2nd Element is the Row which is
  30. 'incremented within the For...Next Loop to retrieve all Values in the 3rd Field
  31. '[Address] contained in varEmployees
  32.  
  33. For lngRecNumber = 0 To lngNumOfRecords - 1
  34.   Debug.Print varEmployees(2, lngRecNumber)
  35. Next
Nov 7 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.