Combo Box & SelText

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

I have a combo box that I use to pull values from another
table. This works fine in my current form.

For instance:
+---------------------------+
| +------------------+ |
| | Value 1 in combo| |
| | Value 2 in combo| |
| +------------------+ |
| |
+---------------------------+

Pretend the box that has Value 1... in it is the
dropdown. When I select "Value 2 in combo" it put it in
the combo box (named mycombo1) as expected. I can close
the form and reopen it and it is there just fine.
When I try to use mycombo1 in a report, it puts the index
value it the report instead of the Text Value.
Ok so trying to be sneaky, I use an event procedure that
runs this code when an OnChange occurs to the mycombo1
box:
Private Sub mycombo1_Change()
[TheTextFrom_mycombo1] = [mycombo1].SelText
End Sub

But when I do this I get an error:
Run-time error '2465'
Microsoft Access can't find the field '|' referred to in
your expression.

Any ideas how I can just use the combobox to put the TEXT
values in my table instead of the index to the text
values?

Any of this make sense?

Thanks,
Tim
 
You don't mention how many columns you have for this combo.

So, in the after update event of the combo box, you can simply go:

TheTextFrom_mycombo1 = mycombo1

The above is all you need. Also, check the "bound collum" setting. If you by
mistake placed a "0" in that value, then the combo box will always return
the index value. The bound collum properity should be set to 1, and then the
combo will return the text value.

On the other hand, if you have a multi-collum combo box, then OFTEN we store
the primary key value, but dispplay, and search via the text value. In that
case, you can use:


TheTextFrom_mycombo1 = mycombo1.Column(1)

Note that the column propoerty is zero based, so the above would pull the
text value, and not the primary key id.
 
I neglected to say that the combobox is in a subform...
I tried what you said, and it still give me same error.

Lets say for arguments sake I can live with it storing
the index, how can I use that value to write query's that
return the text value that is in column 1?
Here is a sample SQL query from access:
SELECT MedPro_Contacts.FirstName,
MedPro_Contacts.LastName, Orders.Type_to_send
FROM MedPro_Contacts INNER JOIN Orders ON
MedPro_Contacts.ContactID = Orders.ContactID;

The combobox value is Orders.Type_to_send. It does
return the correct index value, but I'd like it to return
the text value.

Any help would be appreciated.

Tim
 
Back
Top