Techniques

mdmilner

Well-known Member
Joined
Apr 30, 2003
Messages
1,362
Here's a question about technique.
Although the books tend to start people out by referencing fields dynamically by name, I've found alot of uses for Absolute references to specific columns.

One of the more common uses tends to be when I need to walk through a recordset and want to iterate through all the fields regardless of number (as sometimes the scope of the project changes and I have to add fields)

Using references like:

rs.Fields(x).Value or rs.Fields(x).Name

The latter (.Name) I tend to use when building SQL queries and I know that I need the first two fields and then column 5-7, for example.

Thoughts?

Is there more processing time involved in using:

With rs
.Fields(x).Name
End With

vs

With rs
!fieldName
End With

Mike
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi Mike

According to Getz, Litwin and Gilberts' "Access 2000 Developers Handbook" (the Access Bible if ever there was one) ...

It turns out that, behind the scenes, the...dot-and-bang reference is translated to the...style of parentheses-and-quotes reference when you execute...a ststement. This means that, although using the bang operator will save you a bit of typing, you'll pay for it in a speed penalty.

Page 233 of the paperback issue, published 1999.

Their style is to use the brackets-and-quotes unless a bang(!) is absolutely necessary ('though no examples are given where that may be the case).

anvil19
:eek:
 
Upvote 0
And here I was completely ignoring one method (syntax)
The two I use overwhelmingly are (first field in table):

rs!fieldname1
rs.fields(0).value

The third is, of course:

rs.fields(fieldname1).value

So, which is it translated to precisely? #2 or #3?
Or could #2/#3 be identical in terms of processing speed?

My use of the words "relative" and "absolute" were me applying excel-speak to cell referencing to Recordsets. When you reference a field by it's name, you only get the field. When you reference by a number, you get that column no matter what the name might be. Sometimes, the latter is useful.

Mike
 
Upvote 0

Forum statistics

Threads
1,221,631
Messages
6,160,942
Members
451,679
Latest member
BlueH1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top