3

The Requirement... I've a massive VB6 Project with tons of forms in it. One parent MDI form and all other forms open inside it from different menu actions.

I need to split this project, say keep the main form there, and extract other groups of related forms into their own projects.

Lets take example of a fresh project... MainProject:

  • Only one MDI form called, frmMain with menu
    • Menu Item 1
    • Menu Item 2

prjModule1

  • To have a form frmModule1Main, which needs to be loaded as MDI child of frmMain when menu item 1 is selected

prjModule2

  • To have a form frmModule2Main, which needs to be loaded as MDI child of frmMain when menu item 2 is selected

How can I achieve this, what should be the project types of each project? the main one I understand should be Standard Exe, but what about the other two? Do I need exe or dll?

I tried the following

Standard Exe project: MainProject, with one MDI parent form DLL Project child1:

  • Has a public a public class, and a form.
  • exposed a method from Class "ShowForm"
  • In the MainProject, added a reference to the child1 project
  • Invoked ShowForm on menu click
Private Sub mnuModule1_Click()
    Dim cls As New prjModule1.Class1
    cls.ShowForm
End Sub

and this is the ShowForm sub

Public Sub ShowForm()
    Dim localForm As New frmModule1Main
    localForm.Show
End Sub

When I select the Module1 menu item, the form prjModule1.frmModule1Main opens as expected. But is not the child of main MDI form. If I change the MDIChild property of frmModule1Main to True. I get the error "No MDI form available to load"

What am I missing, how can I tell the child form who is your MDI parent? And that it is already loaded?

Brian M Stafford
  • 8,483
  • 2
  • 16
  • 25
Raheel
  • 421
  • 1
  • 4
  • 7
  • 2
    What is the rationale for splitting things up into sub projects? – StayOnTarget May 05 '23 at 15:01
  • See [this thread](https://microsoft.public.vb.general.discussion.narkive.com/dug4P3jn/vb6-firing-dll-based-forms-as-mdichild), _the most common workaround is to create the "form" as a UserControl, then either embed or create that at runtime on an actual MDIChild form._ – Étienne Laneville May 05 '23 at 15:31
  • I second @StayOnTarget's question: what's the _logical_ goal/purpose you want to achieve? You told us what your _technical_ goal is. But there may be better technical ways to achieve the purpose. – Hel O'Ween May 08 '23 at 08:04

1 Answers1

0

As was pointed out in the comments, you need to convert your Forms to UserControls and embed those UserControls in a project of type ActiveX Control. I could not get any other combination to work.

In the code snippet, frmChild is a MDIChild Form with no controls on it. When you want to show a "form" contained in another project you dynamically add that "form" to frmChild. Here Project1 is adding a "form" from Project3:

Private Sub ShowForm()
   Dim f As frmChild
   Set f = New frmChild
   Dim uc As UserControl3
   Set uc = f.Controls.Add("Project3.UserControl3", "UC3", f)
   uc.Visible = True
   f.Show
End Sub

enter image description here

Brian M Stafford
  • 8,483
  • 2
  • 16
  • 25