質問

I need to pass a ComboBox to a method in a different class module. First I defined the method in the class module as:

Public Sub initializeCombo(ByVal s As String, ByRef c As ComboBox)

And called it from a form:

initializeCombo(s, frmMyForm.cboBox)

This results in a type mismatch. This works if I define the method in the code behind the form, but not in a separate class module.

役に立ちましたか?

解決

It's a mismatch because OptionButton is not ComboBox. Try to change it into ByRef c As OptionButton.

You can figure that out by replacing ByRef c As ComboBox with c As Variant, then set a breakpoint on the first line and check on the watch window what is being passed. This usually helps understand what's going on when the object passed is not the expected type.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top