tags:

views:

122

answers:

3
dim rs As ADODB.Recordset
...
...
...
capture_id = rs.Fields(0)

what does .Fields(0) mean?

+3  A: 

It's pulling the first column from the current row in the result set.

Fields(x) lets you access fields by a numerical index starting at 0.

Edit:

Example:

If the result set has two columns: foo and bar..

rs.Fields(0) would return the value of column foo,

and

rs.Fields(1) would return the value of column bar.

Matt
sorry can you give me an example
I__
@every_answer_gets_a_point - see my edit for an example. Not sure I can make it clearer than that. Pretend the columns in the current row are like arrays, which are also indexed starting at 0.
Matt
+3  A: 

the first column from the recordset (0) is the first (1) is the second etc etc

example, if this is your query

select LastName, FirstName 
from YourTable

In this case s.Fields(0) would return column LastName and rs.Fields(1) would return column FirstName

SQLMenace
sorry can you give me an example
I__
+1  A: 

I would NEVER, EVER use this syntax. This depends on the query always having the same field in the first position.

Furthermore this would only savea a minute amount of time. (As in milliseconds if not less.)

Please. for the love of God, err proper programming practice, change that to use the field name. This almost, but not quite, belongs on the www.dailywtf.com website.

Tony Toews
@Tony Agreed this is not normal to see. The only time I have ever used this is during a loop that opened a set SQL statement and then looped, its only going to save a fraction of a millisecond so if you are only doing it once there is no point. Also I might add there is a comment right above the line in my loop to explain what the field numbers are to aid future debugging!
Kevin Ross
@Tony "Never, Ever" does seem a little strong. In this case, I believe it is being used to get the last inserted @identity. Access can also be used for data analysis and data cleaning, where you might have need of "for each field in each table".
Remou
I respectfully disagree with your first sentence. In this case I would never, ever use such a syntax. Now with your second sentence fine as you are looping through all the fields then yes but that's clearly not the case here. I've used that syntax myuself for a 500 line routine which exports the contents of a recordset to Excel and does lots of cleanup and formatting. But that's not the case with the original code.
Tony Toews