Get Value by Column Name in RecordSet

  • Thread starter Thread starter XMan
  • Start date Start date
X

XMan

I know how to get value of a record in record set by RecordSet(index). Is
there a way to get by column name like RecordSet("ColumnName"")? TIA.
 
If rs is an open recordset containing one or more records:

rs(0) returns the value of the first field in the current record;

rs("blah") returns the value of the field named "blah" in the current
record;

rs.movenext moves to the next record in the recordset.

HTH,
TC
 
XMan said:
I know how to get value of a record in record set by RecordSet(index). Is
there a way to get by column name like RecordSet("ColumnName"")?

As far as I know, a record has many values, so your
RecordSet(index) does not return the value os a record. It
will return the value of the field with that index. The
default collection of a DAO recordset object is the FIelds
collection, so what you wrote is the equivalent of:

Recordset.Fields(index)

If you want to refer to the field by name, then you can use
the name of the field as the index:

Recordset.Fields("ColumnName")

which, as you presumed, can be abbreviated as:

Recordset("ColumnName")

or the alternate syntax:

Recordset!ColumnName
 
Back
Top