views:

105

answers:

1

i'm working on a MS access database..

At some point i needed to create a module which contains a dynamic string array, the data to store in this array should be brought from a table, i use count(*) function on that table to define the size of the dynamic array.

what i need to know is how to fill the array with the contents of a columns of that table ( called Names);

to make it more clear: suppose i declared the array like this

dim myArray() as string
redim myArray(myTable.count(*))

where my table contains two fields: ID, Name

i want myArray(0) to hold the content of Name in the first record myArray(1) to hold the content of Name in the second record

and so on

how to do this?

+2  A: 

I am not sure why you would want to use an array, but here is a way adapted from a Microsoft article:

Dim objConnection as ADODB.Connection
Dim objRecordSet as ADODB.Recordset
Dim arrTest as variant

Set objConnection = CurrentProject.Connection
Set objRecordSet = New ADODB.Recordset

objRecordSet.Open "SELECT * FROM YourTable" , objConnection, _
    adOpenStatic, adLockOptimistic

arrTest = objRecordSet.GetRows

objRecordSet.Close

objConnection.Close
Buggabill
I agree that this is the solution, but, Ala ABUDEEB, why would you want to do this?
Remou
@Remou: because i want my database to be dynamic for users.It is a simple accounting database, i want to enable the user to add as many accounting sections as he wants without always asking a developer to do that, for example, to add a section for export accounting, and one section miscellanous. so the new accounting section name should be added to a table, then the array takes these contents and modifies the database as required
Ala ABUDEEB
I still do not see why you need the array, can you not simply update the table? I often allow users to add 'sections' with, for example, a combo box and the NotInList event.
Remou
Remou
Assuming using an array is required, which I doubt, I'd use a User Defined Data Type instead of an array. Although you'd probably have to fill it by looping through the recordset.
Tony Toews