Solved

VB 4.0 How to load a form by VarName

Posted on 1998-12-10
5
129 Views
Last Modified: 2011-09-20
I want to read the name of the last loaded form out or a .ini-file. Then I want to load the form.

For example:
the last form was 'frmTest'. I read the name into gsForm.
Now I want to load the form 'frmText'.

I can't use the code
 For x = 0 to Forms.Count-1
    ...
 Next x

because it only works with the forms already loaded.
What's to do?
0
Comment
Question by:koz2355
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:caraf_g
ID: 1449256
Before I can answer your question, I would like to have a bit more information.

1 - Do you refer to your form frmTest by its design time name?
    for example
    frmTest.Show vbModal
2 - Do you instantiate your form through object variables?
    for example
    Dim myForm As frmTest
    Set myForm = New frmTest
    myForm.Show vbModal
3 - Do you wish to re-display a form with its old contents or do you intend to create a new instance of the form?


0
 

Author Comment

by:koz2355
ID: 1449257
Hi caraf_g,

frmTest was an example. the formname could be any form in my application the user can work with. For better understanding:
dim gsForm as string
gsForm = "frmTest"
gsForm.Show <- something like this

greetings
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1449258
Sorry, not possible. The only thing that you can do is have an switch statement and test on the name and make an instance of this form.
0
 
LVL 10

Accepted Solution

by:
caraf_g earned 20 total points
ID: 1449259
Having only used VB5 myself I can't guarantee that the following will work. I hope it is possible in VB4 to Dim variables As Object, and that you can use the Set keyword in VB4.

If you can, this might work for you:

Dim gobjForm As Object
Dim gsForm As String

Select Case gsForm
Case "frmTest"
    Set gobjForm = New frmTest
Case "<other form>"
    Set gobjForm =.... and so on
.
End Select

All the best, and good luck
0
 

Author Comment

by:koz2355
ID: 1449260
Hi caraf_g,
it works. Thank you very much.
greetings
koz2355
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

707 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

13 Experts available now in Live!

Get 1:1 Help Now