Solved

Calling a form from variable

Posted on 2002-05-16
5
160 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 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

27 Experts available now in Live!

Get 1:1 Help Now