Solved

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

Posted on 2002-07-04
7
137 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
Comment Utility
Try this

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

Expert Comment

by:pierrecampe
Comment Utility
'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
Comment Utility
This way:

Private Sub Form_DblClick()
    Dim x As Form
   
    Set x = Forms.Add("form2")
    x.Show
End Sub
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:xBxRay
Comment Utility
-----------------------------------------
-> 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
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

8 Experts available now in Live!

Get 1:1 Help Now