ComboBox Dropdown not under control

O

OssieMac

ComboBox on a Userform.

I am using the following code to display the dropdown list for a ComboBox
when the user enters the ComboBox. However, when the form opens, the dropdown
list for the first Combo box is towards the top left of the screen outside of
the Userform instead of under the ComboBox control on the Userform. This
occurs in both xl2002 and xl2007. If I reduce the size of the Excel window,
the dropdown can be completely off the Excel window also.

I can actually make a selection form the dropdown.

It is almost like the drop down list is positioned relative to the top left
of the screen instead of the userform.

Any help to fix this problem will be greatly appreciated.

Private Sub ComboBox1_Enter()
If Me.ComboBox1.ListCount > 0 Then
Me.ComboBox1.DropDown
End If
End Sub
 
O

OssieMac

I now have a workaround for this in the following code example. Just set the
focus to another control that does not have an Enter event and then set it
back to the first combo box.

I feel fairly sure that what is occurring is that the dropdown is being
displayed before the form is painted and hense Excel does not know where to
position it and it gets positioned relative to the screen Top and Left
instead of the Form Top and Left.

Still interested (just curiosity) if anyone has another explanation or
alternative workaround.

Private Sub UserForm_Activate()
Me.CommandButton1.SetFocus
Me.ComboBox1.SetFocus
End Sub
 

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