473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Cycle though fields of a recordset

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
4 26178
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Melissa | last post by:
I have a frontend file named CustomerApp and backend file named CustomerData. CustomerApp is at C:\Customer Database and CustomerData is at S:\Customer Database. Could someone help me with the code...
3
by: alex_peri | last post by:
Hello All, I am having problems with sorting a recordset by fields in Access. I have a table with three columns called ID, SNo and Time and would like to sort the records by Time. I would like to...
6
by: Brian | last post by:
Hello, Basically, I'm running a query on a form's activation, and I'd like to have the results of the query be placed into other fields on the same form automatically. Does anybody know how...
16
by: Feico | last post by:
Dear friends I am an experienced programmer, but I happen to have MS Access, which uses a language unknown to me. I want to perform an operation on all record on a table, like this For...
0
by: Gian Paolo Clarici | last post by:
I'm migrating one Asp page to Aspx. There is a recordset and I need to Reponse.write the content of one of its fields . That field comes from a Numeric(5,2) SQL datatype Its content is : 90.00 ...
24
by: Donald Grove | last post by:
I want to populate an array with values from an ado recordset (multiple rows) I use the absolute position of the cursor in the recordset to define the row of my array to be populated. I have a...
7
by: ammmmmu | last post by:
Hi all, I am using VB 5.0 and msaccess as a database, I am reading the data from logfiles and inserting it in db, its not throwing any error, but after excecution I not find any records in table...
1
by: sphinney | last post by:
All, I have a ADODB.Recordset in my Access 2002 project. I've been able to successfully add fields to the record set. According the the MS Access help files, I now must update the recordset to...
3
LBryant
by: LBryant | last post by:
First of all, I want to say how thrilled was to find this forum and how much I value the expertise here. Now, here's my quandry. I have a form bound to a query that pulls a single record from a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.