I have a query OUTPUT with cols DATE, TYPE, VALUE. I need to gather all the different dates into a variable so I can later create a CSV file for each unique DATE. I tried creating a record set, and assigning the values of DATE to a variable as such:
Sub GetDates()
Dim rst As Recordset
Dim db As Database
Dim arrDates As Variant
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT Date FROM OUTPUT GROUP BY DATE; ")
arrDates = rst.GetRows()
but when I do:
For Each Item In arrDates
Debug.Print (Item)
Next
I only get one date printed (11/01/2012). If I run the query in Access, I see all 15 months.
Do While Not rs.EOF ... Loop? - FionnualaGetRows()fetches one row unless you tell it to fetch a different number of rows. See the help topic for details. - HansUpSELECT DISTINCT Date FROM OUTPUThere because you are grouping by all outputted columns and you are not applying any aggregate functions. It just seems more natural to do so. - Olivier Jacot-Descombes