문제

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