Excel VBA - Copying Recordset to Array


  • I for the life of me cannot figure out how to do, what I figure, should be a simple task; I need help on how to copy the contents of a recordset to an array in VBA.  I have my recordset ready to go, but I have no clue on how to copy it's contents to an array. 


    In my routine, I want to access this array to find out if a date already exists in the db before inserting the new data, so I only have one column in my recordset.


    Also, why I'm here, what would be the best way to compare two dates that have a differing format and what should I make my array for a date...I'm guessing a date array?


    Thanks for the help!

    Thursday, April 12, 2007 7:19 PM

All replies

  • Hi,


    You can use recordset's GetRows method to retrieva data to an array:




    However, if you need only to check if a date exists, you can use FindFirst method (in DAO recordsets) or Find method (in ADO recordsets), or even opening a filtered recordset:

    "SELECT MyField FROM myTable WHERE MyField=#" & Format(myDateValue,"m/d/yyyy") & "#"

    Friday, April 13, 2007 2:48 AM