ComboBox - Different Text & Value Properties

M

Mike

Hi. I'm an ASP.NET developer working on an Access application. In ASP.NET
I'm used to a dropdownlist's DataTextField property (text that displays in
the control) and DataValueField property (the value tied to each text item).

In Access, how can I set both a text and value property to a combobox?
Specifically I have a ComboBox control that I need to have display text field
"UserName" and have a value named "UserID". Is this possible?

I am using a combobox's rowsource to write the select statement which
populates the combobox. Can I set both a text and a value for the combobox?

Thanks.
 
K

Klatuu

You're working in a different world here. The Text property is seldom used
in VBA. It only has value when a control has the focus. The Value property
is another that is seldom used explicitly, because it is the default
property, so:

x = Me.MyCombo
x = Me.MyCombo.Value

Are equivilant.

Now, to answer your question, if you want to have a display value and a
value that is hidden, but you need to use. You use a combo with more than
one column. Although it isn't necessary, I suggest setting it up this way.

Make the display value the first column and the other value the second column.
Set the Bound Column property to 1
Set the Column Count property to 2
Set the Column Widths property to 1.5"; 0"
The 1.5 can be whatever width works for your display column, the 0"
for the other column makes it invisible.

Now, when you have made a selection, you can return the value of the display
column with
Me.MyCombo
And you can display the other value with
Me.MyCombo.Column(1)

Me.MyCombo.Column(0) is the same as Me.MyCombo
The column collection is 0 based.
 
M

Mike

Thank you so much!

Klatuu said:
You're working in a different world here. The Text property is seldom used
in VBA. It only has value when a control has the focus. The Value property
is another that is seldom used explicitly, because it is the default
property, so:

x = Me.MyCombo
x = Me.MyCombo.Value

Are equivilant.

Now, to answer your question, if you want to have a display value and a
value that is hidden, but you need to use. You use a combo with more than
one column. Although it isn't necessary, I suggest setting it up this way.

Make the display value the first column and the other value the second column.
Set the Bound Column property to 1
Set the Column Count property to 2
Set the Column Widths property to 1.5"; 0"
The 1.5 can be whatever width works for your display column, the 0"
for the other column makes it invisible.

Now, when you have made a selection, you can return the value of the display
column with
Me.MyCombo
And you can display the other value with
Me.MyCombo.Column(1)

Me.MyCombo.Column(0) is the same as Me.MyCombo
The column collection is 0 based.
 

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