Solved

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

Posted on 2002-07-04
7
141 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 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

810 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