Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

createobject to instance a vb6 form?

Posted on 2006-06-21
4
Medium Priority
?
1,378 Views
Last Modified: 2008-02-01
Hi

Is there any way to instance a vb6 form using only the name of the form in vb6?

eg: set frm = createobject("form1")

(this doesn't work)

I want to be able to instance a form from it's name which will be stored in a string.
0
Comment
Question by:daniel_j_c
  • 2
4 Comments
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 16949534
trY:

dim frm as form1
set frm = new form1
...
0
 
LVL 2

Author Comment

by:daniel_j_c
ID: 16949659
ok, here's a little background...

I want to be able to store the names of forms in a database in a "tasks" table. The tasks table has the name of the form to be instanced and an associated task name eg:

Form                    Task Name
frmclientdetails      New Client

I want to be able to create an instance of the form frmclientdetails using the string "frmclientdetails". I can't use "= new frmclientdetails" because that would require me to create a select case statement like this:

select case FormName
case "frmclientdetails": set frm=new frmclient details
...
end select

Which is why I want to use something like createobject().
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 16951477
Something like...
   
    Private Sub Command1_Click()
        Dim frmName As String
        frmName = "Form2"
   
        Dim frm As Form
        Set frm = Forms.Add(frmName)
        frm.Show
    End Sub

0
 
LVL 2

Author Comment

by:daniel_j_c
ID: 16951531
can't believe it's that simple! i've been looking for something like this for years!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Screencast - Getting to Know the Pipeline

824 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