I’m loading a 2 column table into a 2 column combobox, column 2 is the bound column. I want to have the form open with a combobox item already selected. I’m having success with Macro1, but in Macro2 the line .cmb1.Value = 4 raises an error. I’m not sure why that is, could someone give me an explanation?

Sub Macro1()
Dim f As myFrm
Set f = New myFrm
With f
.cmb1.RowSource = [myLst].Address
.cmb1.Value = 4 'displays Wed in combo
End With
f.Show
End Sub
Sub Macro2()
Dim f As myFrm, v
Set f = New myFrm
With f
.cmb1.List = [myLst].Value
.cmb1.Value = 4 'Error
End With
f.Show
End Sub
Good question. Here's the relevant part of Excel VBA 2010 help:
For a ComboBox, changing the contents of Value does not change the value of BoundColumn.
Not that you need it, but here's an alternative:
With f.cmb1
.List = [myLst].Value
For i = 0 To .ListCount - 1
If .List(i, 1) = 4 Then
.ListIndex = i
Exit For
End If
Next i
End With
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With