?
Solved

Open form by its name

Posted on 2004-11-23
6
Medium Priority
?
146 Views
Last Modified: 2010-05-02
how can i open unloaded VBForm by its name like:

forms.("FormName").show .... or any way
0
Comment
Question by:shinfotec
6 Comments
 
LVL 15

Expert Comment

by:Colosseo
ID: 12653801
Hi

how about

FormName.Show

Scott
0
 
LVL 15

Expert Comment

by:Colosseo
ID: 12653951
Or if you meant where you have the name as a string you could try this

' Add the form to the forms collection
Forms.Add "FormName"

' Show the form with the highest index (which is the last added and in this case FormName)
Forms(Forms.Count - 1).Show

Cheers

Scott
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12653988
Or do you not want to 'hard-code' the form name (is it, perhaps, stored within a string)?

If so, try:

    Sub OpenFormByName(ByVal sFormName As String)

           Dim frm As VB.Form

           For Each frm In Forms
              If frm.Name = sFormName Then frm.Visible = True
           Next frm

    End Sub

Now just open the form, with

    OpenFormByName("myFormName")

Although, you will have to have loaded all forms beforehand, in an initialisation routine, as Forms collection only contains the loaded forms.

HTH

J.
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!

 
LVL 19

Expert Comment

by:Shauli
ID: 12654303
Dim myFormName As String, NewForm as Form

'to show the form
    myFormName = "Your form name"
    Forms.Add (myFormName)
    Set NewForm = Forms(Forms.Count - 1)
    NewForm.Show

'and when you unload the "NewForm" add this line to your code

Set NewForm = Nothing

S
0
 
LVL 18

Accepted Solution

by:
JR2003 earned 2000 total points
ID: 12654454
Instead of the following lines in the previous example:
Forms.Add (myFormName)
Set NewForm = Forms(Forms.Count - 1)

You can save a line of code by just using:
Set NewForm = Forms.Add(myFormName)
0
 
LVL 11

Expert Comment

by:Louis01
ID: 12664134
 Dim frm As Form
 
  For Each frm In Forms
    If frm.Name = "myLoadedForm" Then
      frm.Show vbModal
    End If
  Next


This depends on the form already being loaded
0

Featured Post

Technology Partners: 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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…
Suggested Courses

807 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