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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of Culomns

Status
Not open for further replies.

coughnut

Programmer
Dec 6, 2005
27
US
I am importing an Excel spread sheet to a table in Acess. I am then searching every single row and column of that created table in VBA. What I would like to know is, is there a way to find out how many culomns, fields, a table has in VBA. I will be importing spreadsheets that would vary in the number of columns it has. For that same reason I would like to know how many columns the table has,becasue I get an error: "Item cannot be found in the collection corresponding to the request or ordinal"

This happens in my design when I reached the last column in the table and I try to read a column that doesn't exit.
Here is the line that I am using that gets that error:
strHolder = rsTemp.Fields(indx)

Does any one have any ideas... Thank you very much.
 
If you're using DAO recordsets and database references...

How about:
Code:
Dim fld as DAO.Field
Dim fldCount as Integer

fldCount = 0
For Each fld In rsTemp.Fields
     fldCount = fldCount+1
Next fld

There probably is a better way to do this, but this is what I KNOW how to do.

-Pete
 
As in:
[tt]For i = 0 To rs.Fields.Count - 1
Debug.Print rs.Fields(i)
Next[/tt]
 
Or alternatively:

CurrentDB.TableDefs("TableName").Fields.Count

Ed Metcalfe.

Please do not feed the trolls.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top