Search code examples
excelvbauserform

VBA - Userform new instance


So I have a main userform where I do all my calculations and I want to display them on my image forms. I tried to use:

Dim newInstance As New diagramGUI
newInstance.Show vbModeless

but then I cant access the data from the main userform. Is there any workaround for this?

enter image description here


Solution

  • You need to add a public variable in the diagramGUI userform to point the the instance of MainUserForm.

    Add this line to the diagramGUI code module

     Public Controller as MainUserForm 
    

    Then set the reference from the MainUserForm after you instantiate then new diagramGUI

     Dim newInstance As New diagramGUI
     Set newInstance.Controller = Me
     newInstance.Show vbModeless