ShawnCoutts
Programmer
I have a program where I need to connect to a data base and pull a number of records out based on a certain criteria. I have managed to successfully connect to, and open the database, and return the required data into my recordset. This is where I begin to have problems. How can I extract the data out of the recordset? I have tried using the GetRows() function, to put the data into an array, and then used recordcount property of recordset to find the number of records. For some reason, recordcount keeps returning -1. Here is my code:
the eventual goal is to take strRec and add it into a listbox control, so that the end user can select it.
Code:
Private Sub TruckNum_Click()
Dim adoCon As New ADODB.Connection
Dim adoCmd As New ADODB.Command
Dim adoRec As New ADODB.Recordset
Dim rec As Variant
Dim i As Integer
Dim count As Integer
i = 0
Dim strRec As String
adoCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Programmer\Desktop\Klassen_Timeslip\klassen.mdb;" 'UserID=admin;Password=;
adoCon.Open
adoRec.ActiveConnection = adoCon
adoCmd.ActiveConnection = adoCon
adoCmd.CommandText = "SELECT * FROM equipment WHERE equipment_type = 1 OR equipment_type = 7 ORDER BY unit_number"
Set adoRec = adoCmd.Execute
count = adoRec.RecordCount
rec = adoRec.GetRows()
Do While i < count
strRec = rec(i, 0)
i = i + 1
Loop
End Sub
the eventual goal is to take strRec and add it into a listbox control, so that the end user can select it.