1

I've succesfully created an UserForm, that implements an Interface which enables showing a warning tooltip (https://youtu.be/8dvWjXgVpxk). It is working just fine when all user forms, modules and classes are located in one common project, but now I'd like to take the Interface and store it in another project, which I could then reuse in many different projects by creating reference to it (Tools -> References). Unfortunately, when I transfer the Interface and an UserForm that this Interface uses as a member variable, I'm getting an Compile error: "Private object modules cannot be used in public object modules as parameters or return types for public procedures, as public data members, or as fields of public user defined types." error message

I'm struggling with this few days now, and cannot find a propper approach.

The simplified code structure:

Main project:
module: UFManager:

Sub CATMain()
    UFThatHasTooltip.Show
End Sub

user form: UFThatHasTooltip:

Implements ICanShowTooltip

Private Sub UserForm_Click()
    Debug.Print "click!"
End Sub

External project:

class/interface: ICanShowTooltip:

Public myTooltip As UFTooltip

user form: UFTooltip

'empty

I think the main issue is caused by the fact, that the userform UFTooltip is considered Private and thus cannot be used in any form by anything that works as Public. I know how to solve this issue, when instead of user form I'd like to use a class as a member variable of an interface (by changing 'Instancing' property of the class from '1 - Private' to '2 - PublicNotCreatable'), but I cannot find a property of an user form that changes its behavior to 'Public'.

PS. I know that the userform UFThatHasTooltip is missing some Properties definitions demanded by the use of an Interface, but the compiler doesn't even goes that far to care about it, so I ignored them for now.

EDIT: I've managed to export .frm file of UFTooltip, edit the attribute VB_Exposed and set its value to True. That helped with the initial issue, so I developed the code further and placed it on a repo: https://github.com/hwnd-git/VBA-Interface-Sandbox Now I'd like to know if there is a way to achieve this without the need of exporting the user form and editing its .frm file.

Tomasz
  • 11
  • 2
  • You need a factory that can be used to generate a form object. If you post your form code we can show you how to do that. – freeflow Oct 28 '21 at 20:41
  • @VictorK: It worked! Now - is there a way to achieve the same effect without the need to exporting the UserForm and editing the file to make it public? – Tomasz Oct 28 '21 at 21:21
  • @freeflow I've updated the code further, taking into acount Victor's advice. Could you check the module FactoryTooltip, please? Are you refering to factory as a method/class that has the capability to create an instance of an user form? How to use it in case I ignored Victor's advice and didn't edit .frm file of UFTooltip? I've added the files to a repo so you could access them: https://github.com/hwnd-git/VBA-Interface-Sandbox – Tomasz Oct 28 '21 at 21:22

0 Answers0