-
Hey,
Im in a very big hurry to figure this out.
Ive been trying to get this Getrows Function
to take a row from my Db and put it in a
array but I dont know how!!!!
I need the code really bad..
The info:
Db name = E:\ClientAlert\clients.mdb
Db recordsource = Clients
Db Row = closeing date
I need all the rows to be put into the array 'Dates()'
Please help!!
Evan
-
Here you go. This example is uding ADO, so add a reference to Microsft ActiveX Data Objects 2.x Library.
Code:
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim arrRec As Variant
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.Open "E:\ClientAlert\clients.mdb"
rs.Open "Select [Closing Date] From Clients", cn, adOpenStatic
If Not rs.EOF Then
arrRec = rs.GetRows
End If
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
arrRec is now holding all records from your recordset.
P.S. note that your array is structured like this:
arrRec(Row, Col)
-
(I lost my internet connection while trying to post this and when I got back Serge had already responded. This is redundant info but I'm posting this any way since I already had it put together :eek: )
Here is some code for you to try. Note that you don't Dim the array explicitly as an Array. Since I don't know the Table or Field names in your database, you'll have to modify the strSQL contents to match the fields and tables that you are really pulling data from.
Code:
Private Sub LoadClients()
Dim strSQL As String
Dim rsTemp As Recordset
'This variable will hold the array
Dim arDates As Variant
Dim strConnect As String
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=E:\ClientAlert\clients.mdb;" & _
"User Id=admin; Password=;"
On Error Resume Next
Set rsTemp = New ADODB.Recordset
'I don't know the fields or table names in your
'database so I'm just making the SQL Select up.
strSQL = "SELECT ClientID, Date1, InfoX" _
& "FROM Clients " _
& "ORDER BY ClientID"
rsTemp.Open strSQL, strConnect
'This will put the info into your array.
arDates = rsTemp.GetRows
'Clean up
rsTemp.Close
Set rsTemp = Nothing
End Sub
Now (if I didn't screw up the code :( ) you should have the data in an array named arDates.
Hope this helps. :)
[Edited by jcouture100 on 04-17-2000 at 10:30 PM]