The problem is the parentheses used when you call the Sub:
c.casttoarray (r)
These evaluate r
and so pass the default member of the Recordset class (which is the Fields collection) to the procedure.
Remove them or use call;
c.casttoarray r
call c.casttoarray(r)
Or strongly type the casttoarray
argument.