Solved

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

Posted on 2002-07-04
7
150 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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 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 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses
Course of the Month11 days, 5 hours left to enroll

631 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