Solved

loading new copies of a form

Posted on 2004-10-03
12
161 Views
Last Modified: 2010-05-02
I have a program which has a menu system similar to the start menu used by windows. but because my forms dont have boarders i cant use the menu editor. So therefore i have made a system using forms. but the problem is I cant load another instance of the same form without the other one disappearing. I know u can use MDI forms but i cant take the boarder off the MDI form. Any ideas?
0
Comment
Question by:schoi_ukuk
  • 4
  • 3
  • 2
12 Comments
 
LVL 19

Expert Comment

by:Shauli
Comment Utility
Dim newForm As Form1    'modify to your form name
Set newForm = New Form1   'modify to your form name
newForm.Show


S
0
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
As an alternative, you could make a standard form with your menu structure.  This form would be loaded, but hidden.  This way you could access the menu using PopupMenu.

ex:

PopupMenu frmHidden.mnuPop1
0
 
LVL 2

Accepted Solution

by:
x_terminat_or_3 earned 25 total points
Comment Utility
The technique described by Shauli is a good way to load multiple instances of the same form.

You should, however, keep track of all instances, and close all of them when closing the program.

This can be done easily with the Collection class

Here's an example.  Change Form1 to the name of the form to be created


Option Explicit
Dim cForms As Collection

Private Sub Command1_Click()
    Dim cForm As Form1
   
    Set cForm = New Form1
   
    cForms.Add cForm
   
    cForm.Show
   
End Sub

Private Sub Form_Load()
    Set cForms = New Collection
   
End Sub

Private Sub Form_Unload(Cancel As Integer)
    'unload all forms
    Dim cForm As Form1, lngCount As Long
   
    For lngCount = 1 To cForms.Count
        Set cForm = cForms.Item(lngCount)
       
        Unload cForm
    Next lngCount
End Sub



With kind regards


Ramses (x_terminat_or_3)
0
 
LVL 19

Assisted Solution

by:Shauli
Shauli earned 25 total points
Comment Utility
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    'unload all forms
    Dim cForm As Form1
   
    For Each cForm In Forms
        If Not cForm.Name = Me.Name Then
               cForm.Hide
              Unload cForm
              Set cForm = Nothing
         End If
    Next
End Sub

This is the correct way to unload all open forms.

S

0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 19

Expert Comment

by:Shauli
Comment Utility
One correction:

Dim cForm As Form
'                     ^^^^

S
0
 
LVL 2

Expert Comment

by:x_terminat_or_3
Comment Utility
both methods are good, although yours is easier...
0
 
LVL 32

Expert Comment

by:Erick37
Comment Utility
If you are loading new instances of the main form, then:

If Not cForm.Name = Me.Name Then '<< Will not work because all the names are the same.

I think you mean to use:

If Not cForm Is Me Then
0
 
LVL 19

Expert Comment

by:Shauli
Comment Utility
Erick37 , Absolutely right.  :)

S
0
 
LVL 2

Expert Comment

by:x_terminat_or_3
Comment Utility
Split Shuili x_terminat_or_3
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now