From: OssieMac on

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

--
Regards,

OssieMac
From: OssieMac on
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

--
Regards,

OssieMac


"OssieMac" wrote:

>
> 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
>
> --
> Regards,
>
> OssieMac