selecting a combo box item programatically

A

Anja

Hey everyone,

I have a drop down combo box that gets its data from a query. It has
an ID field which is also the value field (and is hidden) and first
and last name fields.

So, the query looks like:

SELECT Persons_T.ID, Persons_T.[First Name], Persons_T.[Last Name]
FROM Persons_T ORDER BY [Last Name];

So, what I am trying to do is select an item programatically using
VBA. So, I get an ID and based on this ID value, I want to select the
value in the combo field.

I tried something like:

MyCombo.Value = ID. However, that does not seem to work. Do I have to
loop over all the combo list values and compare the Value field and
then set the selected value or is there a better way to do it?

Thanks for any help you might be able t give me.

Best,
Anja
 
P

Perry

Statements like below lines of code should work.
You can select a value and pass this to a combo without problems, provided
the passed value coïncides with a boundcolumn value of yr combo.

Dim ID As Long
ID = 38
Me!MyCombo = ID
(assuming 38 is a valid ID in the target table/recordsource of the form)

If this isn't working, there's something else bugging you.
In such case, repost more surrounding info and specify what you want achieve
Info on which Access version would be convenient as well.

Krgrds,
Perry
 

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