Solved

loading new copies of a form

Posted on 2004-10-03
12
170 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

860 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