Solved

loading new copies of a form

Posted on 2004-10-03
12
164 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 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