Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Calling a form from variable

Posted on 2002-05-16
5
Medium Priority
?
199 Views
Last Modified: 2010-05-02
How to call a form if form name is stored in a variable

dim lsFormName as String
lsFormName = "frmTest"

How can i call this frmTest form.

I need this bcoz my form names are stored in a database and the menu is dynamic.
0
Comment
Question by:GautamMukherjee
[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
  • 2
  • 2
5 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 300 total points
ID: 7013407
   Dim TheNewForm As String
    Dim t As Form
    TheNewForm = "MyForm2"
    Set t = Forms.Add(TheNewForm)
    t.Show

Use this to add the new form to the forms collection and then show it.
0
 
LVL 1

Expert Comment

by:Madmarlin
ID: 7013433

Try this

    Dim FormName As String
    Dim frmForm As Form
    Dim FormIWant as form
   
    On Error Resume Next
    ' Search through forms collection to find required form
    For Each frmForm In Forms
If frmForm.Name = strForm Then
            blnLoaded = True
            Exit For
        End If
    Next
   
    FormLoaded = blnLoaded
0
 
LVL 1

Expert Comment

by:Madmarlin
ID: 7013436
Sorry the above code wasnt completed, I sumitted it it error..

Give this a go..

   Dim FormName As String
   Dim frmForm As Form
   Dim FormIWant as form
   
   On Error Resume Next
   ' Search through forms collection to find required form
   For Each frmForm In Forms
       If frmForm.Name = FormName Then
         FormIWant = frmForm  
         Exit For
       End If
   Next
   

You shoudl now be able to reference the form properties from FormIWant.Name, FormIWant.Caption etc

Madmarlin

0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7013437
I suppose actually that the ultimate solution combines both approaches as it is possible that the form you want is already open, if so then MadMarlin's code would work, however this won't add a new form to the collection which mine does.
0
 

Author Comment

by:GautamMukherjee
ID: 7016217
Thanx for the suggestion. Looking forward for more solutions from you.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 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…
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…
Suggested Courses

610 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