Vba – User Defined Type (UDT) as parameter in public Sub in class module (VB6)


I've tried to solve this problem, but can't find any solution. I have a UDT defined in a normal module, and wanted to use it as parameter in a Public Sub in a Class Module. I then get a compile error:

Only public user defined types defined in public object modules can be used as parameters or return type for public procedures of class modules or as fields of public user defined types

I then try to move my UDT in the class, declared as Private. I get this compile error:

Private Enum and user defined types cannot be used as parameters or return types for public procedures, public data members, or fields of public user defined types.

I finaly try to declare it as Public in the class, and get this compile error:

Cannot define a Public user-defined type within a private object module.

So is there any way to have a public UDT used as a parameter in a public sub in a class?

Best Answer

Just define the sub as Friend scope. This compiles fine for me in a VB6 class.

Private Type testtype
  x As String
End Type

Friend Sub testmethod(y As testtype)

End Sub

From your error messages it appears your class is private. If you do want your class to be public - i.e. you are making an ActiveX exe or DLL and you want clients to be able to access the sub - then just make both the type and the sub Public.

Related Topic