Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2002-07-04
7
Medium Priority
?
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 70

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
Industry Leaders: 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!

 

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 70

Accepted Solution

by:
Éric Moreau earned 600 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 70

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

Industry Leaders: 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!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

670 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