1

How to get all the id numbers in database then store all id numbers to array in vb6?

Or is there another way to store all id numbers in one variable only? Because later in the program, I will use the id numbers one by one.

1 Answer 1

4

The GetRows method of an ADO recordset returns an array.

This sample opens the table as a recordset and loads its id values into an array.

Dim rs As Object
Dim varGetRows As Variant

Set rs = CreateObject("ADODB.Recordset")
rs.Open "tblFoo", CurrentProject.Connection
varGetRows = rs.GetRows(, , "id")

I don't know what you want to do with the array, so I'll just examine its values ...

Dim lngUBound As Long
Dim i As Long

lngUBound = UBound(varGetRows, 2)
For i = 0 To lngUBound
    Debug.Print varGetRows(0, i)
Next i

If you're interested in something other than an array, you could use a Collection or Dictionary.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.