Solved

Calling a form from variable

Posted on 2002-05-16
5
146 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
  • 2
  • 2
5 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
Comment Utility
   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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanx for the suggestion. Looking forward for more solutions from you.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now