Problem With Fields Collection

N

Neil

I have some code which has been in place for a while. Now, since I converted
to Access 2002/3 format, it doesn't work anymore. In the code, I set an
object variable of type Field to a particular field in the recordsetclone,
as follows:

Dim fld As Field
Set fld = Me.Recordsetclone.Fields(strField)

where strField is a string variable containing the name of the desired
field.

When this code is executed, I get a "type mismatch" error. Apparently it's
trying to use the value of the field, rather than the field itself.

I checked online help, and it says this:

"With the same syntax forms, you can also refer to the Value property of a
Field object that you create and append to a Fields collection. The context
of the field reference will determine whether you are referring to the Field
object or the Value property of the Field object."

So, according to this, since the context is that I am using "Set" to set an
object variable of type Field, one would think that it would return the
field itself, and not its value, and there would be no problem (as there
hasn't been in the past). But this is not the case.

Has anyone else encountered these problems? Any ideas about what to do here?
Unfortunately, while there is a Value property, there is no Field property
of the Fields collection, or else i'd use it. :-(

Thanks,

Neil
 
A

Allen Browne

Probably the wong kind of Field for the type of Recordset in the form.

If your data comes from Access tables (not linked to another type of
database), try:
Dim fld As DAO.Field

More info on disambiguation of libraries:
http://allenbrowne.com/ser-38.html
 
R

RoyVidar

Neil said:
I have some code which has been in place for a while. Now, since I
converted
to Access 2002/3 format, it doesn't work anymore. In the code, I set
an
object variable of type Field to a particular field in the
recordsetclone,
as follows:

Dim fld As Field
Set fld = Me.Recordsetclone.Fields(strField)

where strField is a string variable containing the name of the
desired
field.

When this code is executed, I get a "type mismatch" error. Apparently
it's
trying to use the value of the field, rather than the field itself.

I checked online help, and it says this:

"With the same syntax forms, you can also refer to the Value property
of a
Field object that you create and append to a Fields collection. The
context
of the field reference will determine whether you are referring to
the Field
object or the Value property of the Field object."

So, according to this, since the context is that I am using "Set" to
set an
object variable of type Field, one would think that it would return
the
field itself, and not its value, and there would be no problem (as
there
hasn't been in the past). But this is not the case.

Has anyone else encountered these problems? Any ideas about what to
do here?
Unfortunately, while there is a Value property, there is no Field
property
of the Fields collection, or else i'd use it. :-(

Thanks,

Neil

Most probably, because of what is the default libraries of the
different versions. Both ADO and DAO have objects calle Field, but
they are different, try

Dim fld As Dao.Field
Set fld = Me.Recordsetclone.Fields(strField)

And ensure DAO is one of the references listed (Tools | References)
 
N

Neil

Yup, that was it. Didn't even think about it being the field type. Thanks!

Funny -- I don't even have ADO referenced. But I think what happened was
that when I converted to Access 2002/3 format, my DAO reference got moved
down to the end of the list for some reason. There was ambiguity between DAO
and my Word object library.

Thanks again!

Neil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top