symbiont
symbiont

Reputation: 1562

MS Access ComboBox.Column - use name instead of index?

i have ComboBox controls with multiple columns as a Row Source in an Access 2007 form. i'm currently getting the selected values out of each ComboBox item this way...

value = ComboBoxName.Column(i) 'where i is the index.

i would like to use the actual names of the columns as with Recordset's...

value = ComboBoxName.Recordset.Fields("columnname")

(please note that this does not work properly on the Recordset's of the ComboBox'es: it only works AFTER the first time the ComboBox is changed)

my questions:

value = ComboBoxName.Recordset.Fields("columnname")

i would like to avoid writing a function and i don't feel comfortable specifying column indices which may change in the future.

Upvotes: 2

Views: 2671

Answers (2)

Steve
Steve

Reputation: 1

PFIELD = Me.Form.Combo6.Column(0, 0)

Upvotes: 0

Fionnuala
Fionnuala

Reputation: 91376

There is no simple way to do this. You can create a recordset, or you can assign values to variable for each column name (FirstCol=0).

As an aside, why would the columns change? If you are using a select statement, the combo will fail if the table is changed.

Upvotes: 2

Related Questions