How to select the first combobox item (ie. Set Combobox.ListIndex = 0)

  • Thread starter JohnM77 via AccessMonster.com
  • Start date
J

JohnM77 via AccessMonster.com

This is probably slapping me in the face, but I can't seem to figure out an
easy way to simply programmatically select the first item in a combobox
dropdown list. I have comboboxes populated with recordsets, of which the
first column is ID number. I use ADO to perform a query identical to the
combobox.rowsource property and then set Combobox.Value =
rsIdenticalRecordset!IDNumber. It works, but there has to be an easier way.

Something like the VB6 method of combobox.ListIndex = 0 seems reasonable. I
found the following technique,

Forms([form name]).Controls([combobox name]).SetFocus
Forms([form name]).Controls([combobox name]).ListIndex = 0

but requiring the control to have focus causes lots of problems. Are there
any alternatives to the two methods I mentioned?

Thanks,
John
 
D

Dirk Goldgar

JohnM77 via AccessMonster.com said:
This is probably slapping me in the face, but I can't seem to figure out
an
easy way to simply programmatically select the first item in a combobox
dropdown list. I have comboboxes populated with recordsets, of which the
first column is ID number. I use ADO to perform a query identical to the
combobox.rowsource property and then set Combobox.Value =
rsIdenticalRecordset!IDNumber. It works, but there has to be an easier
way.

Something like the VB6 method of combobox.ListIndex = 0 seems reasonable.
I
found the following technique,

Forms([form name]).Controls([combobox name]).SetFocus
Forms([form name]).Controls([combobox name]).ListIndex = 0

but requiring the control to have focus causes lots of problems. Are there
any alternatives to the two methods I mentioned?


You can set the combo box's value to the first item in its list like this:

With Forms![form name]![combobox name]
.Value = .ItemData(0)
End With
 
J

JohnM77 via AccessMonster.com

That's it! Thanks, Dirk! I appreciate your help.

-John

Dirk said:
This is probably slapping me in the face, but I can't seem to figure out
an
[quoted text clipped - 14 lines]
but requiring the control to have focus causes lots of problems. Are there
any alternatives to the two methods I mentioned?

You can set the combo box's value to the first item in its list like this:

With Forms![form name]![combobox name]
.Value = .ItemData(0)
End With
 

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