Search code examples
arraysexcelrecordsetvba

Convert recordset into an array


I would like to convert a recordset rs into an array so that I can use it in further code.
rs can have variable rows and variable columns.


Solution

  • If you are using ADODB it is as simple as:

    Dim ret As Variant
    
    ret = rs.GetRows '~~> assuming rs object is populated and set
    
    Debug.Print Lbound(ret, 1), Ubound(ret, 1) '~~> bounds of 1st dimension
    Debug.Print Lbound(ret, 2), Ubound(ret, 2) '~~> bounds of 2nd dimension