Solved

Problem: Call a TForm, but the name of the Form is in a Variable

Posted on 2002-07-04
7
140 Views
Last Modified: 2010-05-02
I have 2 forms: form1 e form2

dim temp as string
temp="form1"
temp.show (How do I do to execute temp.show like it was form1.show?)

thank's a lot
xBxRay

0
Comment
Question by:xBxRay
7 Comments
 
LVL 6

Expert Comment

by:xSinbad
ID: 7130741
Try this

Dim frmName As Form
Set frmName = form1
frmName.Show
0
 
LVL 6

Expert Comment

by:pierrecampe
ID: 7130799
'i dont think you can do that, however
'the following makes it possible 'in a way'
'have 2 forms,Form1 and Form2
'Form1 is the start-up form
'place the following in Form1

Private Sub Command1_Click()
    Showform "Form2"
End Sub

Private Sub Form_Load()
    Load Form2
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Unload Form2
End Sub

Private Sub Showform(Temp As String)
    For Each frm In Forms
        If frm.Name = Temp Then
           frm.Show
        End If
    Next
End Sub
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7130897
This way:

Private Sub Form_DblClick()
    Dim x As Form
   
    Set x = Forms.Add("form2")
    x.Show
End Sub
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.

 

Author Comment

by:xBxRay
ID: 7150241
-----------------------------------------
-> Comment to xSinbad:
[ 1-THIS WORKS WELL, BUT THE FORM Form1 MUST BE LOADED BEFORE
2- EVEN, IF I NEED TO CALL THE SUB ENABLEBUTTON, THEN ANOTHER
FORM1 WILL BE
OPENED! BUT I NEED
JUST 1 FORM1 OPENED AND I NEED ALSO TO USE THE SUB
ENABLEBUTTON LIKE IT IS!


Public Sub  ENABLEBUTTON
 Form1.cmdButton.Enabled = True
End Sub
]
-------------------------------------
-> Comment to pierrecampe:
[1-THIS WORKS WELL, BUT THE FORM Form2 MUST BE LOADED BEFORE
TO ALLOW
Showform TO WORK WELL!
2- EVEN, IF I NEED TO CALL THE SUB ENABLEBUTTON, THEN ANOTHER
FORM2 WILL BE
OPENED! BUT I NEED
JUST 1 FORM2 OPENED AND I NEED ALSO TO USE THE SUB
ENABLEBUTTON LIKE IT IS!


Public Sub  ENABLEBUTTON
 Form2.cmdButton.Enabled = True
End Sub

]
-------------------------------------
-> Comment to emoreau:
[1- EVEN, IF I NEED TO CALL THE SUB ENABLEBUTTON, THEN
ANOTHER FORM2 WILL BE
OPENED! BUT I NEED
JUST 1 FORM2 OPENED AND I NEED ALSO TO USE THE SUB
ENABLEBUTTON LIKE IT IS!


Public Sub  ENABLEBUTTON
 Form2.cmdButton.Enabled = True
End Sub
]
-------------------------------------

Thank's a lot. And, please answer me because it's very important to me. Thank's again.


0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 150 total points
ID: 7150290
This way:

Dim x As Form

Private Sub Form_DblClick()
   if x is nothing then
      Set x = Forms.Add("form2")
   end if
   x.Show
End Sub

and use x whereever you want to use Form2
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7348079
This question appears to be abandoned. A question regarding it will be left in the CleanUp
area; if you have any comment about the question, please leave it here.

Unless there is objection or further activity, one of the moderators will be asked to accept the comment
of <emoreau>.

DO NOT ACCEPT THIS COMMENT AS AN ANSWER.
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7373316
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 about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

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

20 Experts available now in Live!

Get 1:1 Help Now