Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBa ReDim Variable to field count 1

Status
Not open for further replies.

TheFitz

Programmer
Dec 18, 2003
140
GB
Hi All,

I'm trying to define a 2 dimentional array, based on the number of fields in a given recordset.

ie The outcome of the above should be col1 in array is field name (and laterly) col2 is data.

I've got the following code sample, however, its telling me I need to have a constant to define the variable.

I've tried Inet and it seems that I should be able to do it, however, it's not working.

Code as below:

Code:
Sub ReadRecords(strTable As String, dteCriteria As Date, strFieldSrch As String)
Dim rstTable As DAO.Recordset, fldField As Field, intCnt As Integer

Set rstTable = CurrentDb.OpenRecordset(strTable)

With rstTable

    intCnt = rstTable.Fields.Count

    Dim stra(0 To intCnt, 1) As String <- ERROR HERE!!

    For i = 0 To .Fields.Count - 1
        
        MsgBox .Fields(i).Name
        
    Next

End With

End Sub

TIA,

Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
 
I'd try this:
Dim stra() As String
ReDim stra(1, intCnt)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Still didn't work - same error

Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
 
actually I lied!!! It did work, stupidity on my side.

Many thanks for you help, have a star!!

Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top