hello there,

anyone can help...
is this possible?
i have a string value of form names in my DB so when my condition passes, the variable string will take over the value , then that value will call the form(variable) as string.
i got an error when i use this code.

dim objForm as form
dim sValue as string

sValue="frmXXX"

set objForm=sValue
objForm.show

This is what the code looks like... i need to convert the variable string to form object

thanks a lot.

Recommended Answers

All 4 Replies

hello there,

anyone can help...
is this possible?
i have a string value of form names in my DB so when my condition passes, the variable string will take over the value , then that value will call the form(variable) as string.
i got an error when i use this code.

dim objForm as form
dim sValue as string

sValue="frmXXX"

set objForm=sValue
objForm.show

This is what the code looks like... i need to convert the variable string to form object

thanks a lot.

Try using "New"

Dim objForm As New Form

You have to get the qualified type name first i.e. get the right namespace. Then you can create an instance of that name and convert it to a form (since you know it's a form)

Dim objForm As Form
Dim sValue As String
Dim FullTypeName As String
Dim FormInstanceType As Type

' Form class name
sValue = "Form2"

' Assume that form classes' namespace is the same as ProductName
FullTypeName = Application.ProductName & "." & sValue
' Now, get the actual type
FormInstanceType = Type.GetType(FullTypeName, True, True)
' Create an instance of this form type
objForm = CType(Activator.CreateInstance(FormInstanceType), Form)
' Show the form instance
objForm.Show()

If you have your forms in some other namespace, use

FullTypeName = Application.ProductName & "." & "MyNamespace" & "." & sValue

this code is working for me. but i want to open the form once. it seems that this code will open another new form. how this will be used to open a form once.

thanks

It open a new form because everytime you call this code and you don't save any handle, if you save the handles you can call them everytime you need it without create a new istance (like you are doing now)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.