2
votes

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
2

2 Answers

1
votes

I think named ranges must be look like

Range("cmbKeyMetrics").clear
0
votes

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