Solved

loading new copies of a form

Posted on 2004-10-03
12
171 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
ID: 12211544
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
ID: 12211894
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
ID: 12212227
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Assisted Solution

by:Shauli
Shauli earned 25 total points
ID: 12212266
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
 
LVL 19

Expert Comment

by:Shauli
ID: 12212271
One correction:

Dim cForm As Form
'                     ^^^^

S
0
 
LVL 2

Expert Comment

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

Expert Comment

by:Erick37
ID: 12212316
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
ID: 12212328
Erick37 , Absolutely right.  :)

S
0
 
LVL 2

Expert Comment

by:x_terminat_or_3
ID: 12559516
Split Shuili x_terminat_or_3
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

679 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