I have a database (say 17 cols in total, no of rows varies). I would like to read the contents of the last column into an array. How do I open the database and take the values into my array.
You dont' mention which databse you use or which datatype the column has. Anyway the code could look something like:
-----------------------------------------------------------
Dim MyArr() As String, i as long
Set conn = New Connection
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\tmp\test.mdb"
Set Rst = New Recordset
Rst.Open "SELECT MyTextField FROM MyTable1;", conn, adOpenStatic, adLockOptimistic
i = -1
If Not Rst.EOF And Not Rst.BOF Then
Rst.MoveFirst
While Not Rst.EOF
i = i + 1
ReDim Preserve MyArr(i)
MyArr(i) = Rst.Fields("MyTextField"
Rst.MoveNext
Wend
Else
'no records
End If
'clean up
Rst.Close
Set Rst = Nothing
conn.Close
Set conn = Nothing
If i > 0 Then
'do array stuff here...
End If
-----------------------------------------------------------
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.