Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Field Names using ADO

Status
Not open for further replies.

Yazster

Programmer
Sep 20, 2000
175
0
0
CA
Hi,

Having a problem accessing data using the FIELD NAME.

With DAO, I can do the following:
recordset.fields("fieldname")

This gives me access to the data in the field I've supplied.

With ADO, I can't seem to do this, I'm forced to supply an index number with isn't always convenient.

Does ADO support this functionality? If so, how would I access data using a field name rather than an index number?

Any help would be greatly appreciated.

Yazster
 
This is working correctly with my databases


Dim CN As ADODB.Connection, RS As New ADODB.Recordset

Set CN = New ADODB.Connection
Set RS = New ADODB.Recordset

STRCON = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & DBPATH & ";" & "Persist Security Info=False;" & "Jet OLEDB:Database Password=" & PASSWD

CN.Open STRCON

RS.Open "TABLENAME", CN

RS.MoveFirst (not necessary)
MsgBox RS.Fields("fieldname") 'it´s supossed fieldname is a
field of table tablename

rs.close
cn.close


hope it helps you
 
Hi Alma,

Thanks for the info. After researching the problem a bit more, I discovered that my problem isn't actually ADO related.

I have an MDB database, which I connected to in a similar way as you indicated above. Thing is, I know the field names ( i,e. FIELD1,FIELD2,FIELD3 ) and when I tried to access the data with the following line:
RECORDSET.FIELDS(FIELDNAME)
I got the following error message:
Application defined or object-defined error.

I checked the field name in the table, and it definitely exists. When I tried to view the field name with the following line:
RECORDSET.FIELDS(X).NAME
I got the field name with the table name included (i.e. TABLE.FIELDNAME)

This is what was causing the problem, but I still don't see why the table name is being included in the field name. And this isn't applying to all field names in the table, maybe 3 or 4 out of 57.

Any Ideas?
 
Do the field names that are giving you a problem contain a space?
recordset.fields("[field name]") or use the bang operator

Other ways to reference it

recordset("fieldname")
recordset.fields!fieldname
recordset= rstEmployees.fields("fieldname")
recordset.fields("fieldname").value






David Paulson


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top