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

Existence of Field Name in Record Set

P: n/a
I did find reference to the question in a search of google groups, but
I couldn't find a clear answer.

I need, essentially,

if rs.Fields("X") exists Then _
do something

where rs is an ADO recordset and "X" is a particular fieldname

Is there an easy way to do this?

thanks, --thelma
Feb 14 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 14 Feb 2006 02:30:31 GMT, Thelma Lubkin <th****@alpha2.csd.uwm.edu>
wrote:

Yes. I can think of two basic approaches: either iterate over the
Fields collection:
dim f as adodb.field
for each f in rs.Fields
if f.Name = strFieldNameToFind then
'etc.

or try to access a property of that field and handle the error
appropriately:
on error resume next
strName = rs.Fields(strFieldNameToFind).Name
if Err.Number = 0 then
'etc.

-Tom.

I did find reference to the question in a search of google groups, but
I couldn't find a clear answer.

I need, essentially,

if rs.Fields("X") exists Then _
do something

where rs is an ADO recordset and "X" is a particular fieldname

Is there an easy way to do this?

thanks, --thelma


Feb 14 '06 #2

P: n/a
On 14 Feb 2006 02:30:31 GMT, Thelma Lubkin <th****@alpha2.csd.uwm.edu> wrote:
I did find reference to the question in a search of google groups, but
I couldn't find a clear answer.

I need, essentially,

if rs.Fields("X") exists Then _
do something

where rs is an ADO recordset and "X" is a particular fieldname

Is there an easy way to do this?

thanks, --thelma


Try and read the value of .Fields("X"), it will throw error 3265 if the field
does not exist. Use an error handler to trap 3265 and do whatever if the error
is raised.
Wayne Gillespie
Gosford NSW Australia
Feb 14 '06 #3

P: n/a
Tom van Stiphout <no*************@cox.net> wrote:
: On 14 Feb 2006 02:30:31 GMT, Thelma Lubkin <th****@alpha2.csd.uwm.edu>
: wrote:

: Yes. I can think of two basic approaches: either iterate over the
: Fields collection:
: dim f as adodb.field
: for each f in rs.Fields
: if f.Name = strFieldNameToFind then
: 'etc.

: or try to access a property of that field and handle the error
: appropriately:
: on error resume next
: strName = rs.Fields(strFieldNameToFind).Name
: if Err.Number = 0 then
: 'etc.

Thanks to you and Wayne Gillepsie.
Right now I'm using the first method and finding it very
clumsy. I will see if I can make something more 'elegant'
out of throwing an error...
--thelma
: -Tom.
Feb 14 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.