Passing userform controls as function arguments RRS feed

  • Question

  • Why do I get a type mismatch error when I pass a combobox to a function expecting a combobox? I guess the combobox gets coerced (undesirably) to its value and that gets passed in instead. However, you'd think something like cboStates.object would resolve that but it doesn't. I am guessin I need to somehow change the function declaration but I don't know what to

    Public Sub PopulateCarriers(cbo1 As ComboBox)
        Dim x%
        blah1 = blah.blah
    End Sub

    Sub TryBlah
     1:   PopulateCarriers cboCarriers        'cboCarriers is a combobox on the underlying Userform
    End Sub

    Line 1 raises the type mismatch error

    50% of programming is coding. The other 90% is debugging

    Saturday, March 5, 2016 6:37 AM


  • Actually, I did find the answer. In the function definition, I had to prefix combobox with MSForms., as there are 2 implementations of combobox, and of course, the default is not the one desired

    50% of programming is coding. The other 90% is debugging

    • Proposed as answer by David_JunFeng Tuesday, March 8, 2016 8:39 AM
    • Marked as answer by David_JunFeng Sunday, March 13, 2016 1:06 PM
    Saturday, March 5, 2016 7:44 PM

All replies