Selecting first item in a combo box - with code

I

Ian B

I have a form with (amongst other controls) a Calendar control and a
combobox
The combobox rows are appointment time slots available on the date selected
in the calendar.
The combos populate correctly with correct times but I cannot get the combo
to select row 0 after a reselection of the date.
Consequently, if I select a date where the first appointment is at 10.30am,
I get 10.30am showing as row 0 in the combo.
If I then click on another day, where the first appointment is 8.30am, my
code clears the combobox and reloadeds the correct appointment times but it
still shows 10.30am as the selection. Obviously if I then click on combo
and scroll to the top I then see 8.30am.

There must be a simple solution - I've tried using Dmin to get the first
time and set the combo to that, but that fails, - I've even resorted to
sendkeys - how bad is that? and it didn't work!

Any advice appreciated
TIA

Ian B
 
M

Marshall Barton

Ian said:
I have a form with (amongst other controls) a Calendar control and a
combobox
The combobox rows are appointment time slots available on the date selected
in the calendar.
The combos populate correctly with correct times but I cannot get the combo
to select row 0 after a reselection of the date.
Consequently, if I select a date where the first appointment is at 10.30am,
I get 10.30am showing as row 0 in the combo.
If I then click on another day, where the first appointment is 8.30am, my
code clears the combobox and reloadeds the correct appointment times but it
still shows 10.30am as the selection. Obviously if I then click on combo
and scroll to the top I then see 8.30am.

There must be a simple solution - I've tried using Dmin to get the first
time and set the combo to that, but that fails, - I've even resorted to
sendkeys - how bad is that? and it didn't work!


Not sure you really want to actually select (as if user
clicked) any particular item in the combo box.

Normally, the existing entry in the combo box would be
cleared so it would not indicate a selection that had not
been made yet. This is simply a matter of setting the value
of the combo box to Null.

If you really do want to select the first item in the list:
Me.combo = Me.combo.ItemData(0)
 
I

Ian B

Thanks Marshall, when I see the result of setting it to row 0, your
suggestion of setting box to null looks much neater.
Thanks for your help.

Ian B
 

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