By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,773 Members | 2,307 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,773 IT Pros & Developers. It's quick & easy.

Cycle though fields of a recordset

P: n/a
What is the code to cycle through the fields of a recordset starting at the
second field through the last field when the index of the last field is not
expliciyly known?

Thanks for all help!

Steve
Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Your looking for Fields.Count

For lngX = 1 to rs.Fields.Count -1
' do stuff ...
Next

The fields collection is a zero based collection.
Therefore
Field 2 is at index 1
Field n is at index (.Count -1)

Terry

"Steve" <sp**@nospam.net> wrote in message
news:Rh*************@newsread1.news.atl.earthlink. net...
What is the code to cycle through the fields of a recordset starting at the second field through the last field when the index of the last field is not expliciyly known?

Thanks for all help!

Steve

Nov 12 '05 #2

P: n/a
This example uses a loop counter so you can start where you wish:

Function CycleFields()
Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim i As Integer

Set rs = DBEngine(0)(0).OpenRecordset("SELECT * FROM MyTable;")
For i = 0 To rs.Fields.Count - 1
Set fld = rs.Fields(i)
Debug.Print fld.Name, fld.Type
Next
Set fld = Nothing
rs.Close

Set rs = Nothing
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Steve" <sp**@nospam.net> wrote in message
news:Rh*************@newsread1.news.atl.earthlink. net...
What is the code to cycle through the fields of a recordset starting at the second field through the last field when the index of the last field is not expliciyly known?

Thanks for all help!

Steve

Nov 12 '05 #3

P: n/a
Thanks, Terry!

That's what I was looking for.

Steve
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:bm**********@newsreaderm1.core.theplanet.net. ..
Your looking for Fields.Count

For lngX = 1 to rs.Fields.Count -1
' do stuff ...
Next

The fields collection is a zero based collection.
Therefore
Field 2 is at index 1
Field n is at index (.Count -1)

Terry

"Steve" <sp**@nospam.net> wrote in message
news:Rh*************@newsread1.news.atl.earthlink. net...
What is the code to cycle through the fields of a recordset starting at

the
second field through the last field when the index of the last field is

not
expliciyly known?

Thanks for all help!

Steve


Nov 12 '05 #4

P: n/a
Allen,

Thanks for taking the time to provide the whole code. As always,I appreciate
your help!

Steve
"Allen Browne" <al*********@SeeSig.invalid> wrote in message
news:JL*********************@news-server.bigpond.net.au...
This example uses a loop counter so you can start where you wish:

Function CycleFields()
Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim i As Integer

Set rs = DBEngine(0)(0).OpenRecordset("SELECT * FROM MyTable;")
For i = 0 To rs.Fields.Count - 1
Set fld = rs.Fields(i)
Debug.Print fld.Name, fld.Type
Next
Set fld = Nothing
rs.Close

Set rs = Nothing
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Steve" <sp**@nospam.net> wrote in message
news:Rh*************@newsread1.news.atl.earthlink. net...
What is the code to cycle through the fields of a recordset starting at

the
second field through the last field when the index of the last field is

not
expliciyly known?

Thanks for all help!

Steve


Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.