Reputation: 21
I have a combobox in worksheet. After I execute the subroutine cmdUpdateDropDowns()
, there is a pop up error message saying "Object required" Run-time error '424'. This occurs in line 5 (cmbKeyMetrics.Clear
). I am not sure how to define combobox in worksheet. I have named range it cmbKeyMetrics
Public Sub cmdUpdateDropDowns()
strSQL = "Select Distinct [Key Metrics] From [data$] Order by [Key Metrics]"
closeRS
OpenDB
cmbKeyMetrics.Clear
rs.Open strSQL, cnn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
Do While Not rs.EOF
cmbKeyMetrics.AddItem rs.Fields(0)
rs.MoveNext
Loop
Else
MsgBox "No key metrics available.", vbCritical + vbOKOnly
Exit Sub
End If
Upvotes: 2
Views: 1560
Reputation: 2233
If you want to clear your combobox, you need to add a worksheet reference.
Worksheets("NameOfYourWorksheet").cmbKeyMetrics.Clear
See related question on SO-VBA-Excel How to clear ComboBox Items
Upvotes: 0
Reputation: 2055
I think named ranges must be look like
Range("cmbKeyMetrics").clear
Upvotes: 1