Open form by its name

how can i open unloaded VBForm by its name like:

forms.("FormName").show .... or any way
shinfotecAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ColosseoCommented:
Hi

how about

FormName.Show

Scott
0
ColosseoCommented:
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
jimbobmcgeeCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ShauliCommented:
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
JR2003Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Louis01Commented:
 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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.