syntax - how many fields a table has

  • Thread starter Thread starter Gina
  • Start date Start date
G

Gina

Hi.
Is there a generic syntax to find out how many columns or fields a record
has ??

I would like to have a small generic function just taking the tablename as
an argument instead of having to do the fileds stuff for each single table
here's what I've got
___
Set rs = db.OpenRecordset("SELECT * FROM " & strTablename)
Open CurrentProject.Path & "\" & strTablename & ".txt" For Output As #1
'.... here I do not know the syntax for the number of fields and how to go
on
Do While Not rs.EOF
mat = rs("Material") & "|"

If Not IsNull(rs("Use")) Then
use= rs("Use") & "|"
Else
use= "" & "|"
End If

If Not IsNull(rs("Price")) Then
price= rs("Price")
Else
price= 0
End If

Line = mat & use & price
Print #1, Line
rs.MoveNext
Loop
___

any help most appreciated, thanks in advance !
Gina
 
Done what?

The usual way is:
rs.Fields.Count

Or if you don't really care how many there are and just want
to loop through all of them:
For Each fld In rs.Fields
 
Thanks for your input ....

the loop thing I was looking for!!
Gina
Marshall Barton said:
Done what?

The usual way is:
rs.Fields.Count

Or if you don't really care how many there are and just want
to loop through all of them:
For Each fld In rs.Fields
--
Marsh
MVP [MS Access]

done it and it works
thanks

Gina
 
Back
Top