Let's say I have this:
If there is no form named "Form1" will fail to create ...Code:Dim f as Form
Set f = New Form
My question is:
How I can declare sure there is an form with the same name in the project so I will not return an error?
Thanks
Printable View
Let's say I have this:
If there is no form named "Form1" will fail to create ...Code:Dim f as Form
Set f = New Form
My question is:
How I can declare sure there is an form with the same name in the project so I will not return an error?
Thanks
I think u have to select which form will declared for F
for example u have From named frmMain so your code will be:
then u can do what u want for example make the caption of frmMain equal to caption of F,Like this:Code:Dim F As Form
Set F = New frmMain
hope that is what you wantCode:F.Caption = "VBForums"
frmMain.Caption = F.Caption
Regards.
Thanks but that was not what I wanted ...
I will explain better:
I have a function to create a new form ... then put this:
But if the draft is not an exact form called "Form1" is not going to work ...vb Code:
Dim f as Form Set f = New Form1
How do I fix this?
Do I explain myself?
Thanks
Are you trying to create a form at RunTime?
Yes i do :DQuote:
Are you trying to create a form at RunTime?
of course!Quote:
Don't you know the names of the forms in your project?
But I'm trying to make my function as generic as possible.
Creeuna I want a copy of any form of my project.
CallByName could help?
Thanks
You can use callByName to set property values or to call procedures but you can't create forms (or anything else) by using it.
You can do the following but I don't know why you'd want to.
Usage:Code:Public Sub CreateForm(frm As Object)
frm.Show
End Sub
Code:CreateForm Form2 ' Where Form2 is an existing form in your project
Thanks, but it isnt that i found...
I want to create a reply of any Form which is in my proyect, runtime...
Really Thanks
In order to create a new instance of a form/object, you need to use the keyword NEW. And I don't think you can use a variable or reference as the form/object.
How aboutvb Code:
Public Sub ShowForm(ByVal pstrFormName As String) Dim MyForm As Form Set MyForm = Forms.Add(pstrFormName) MyForm.Show End Sub Private Sub Command1_CLick() ShowForm "Form2" End Sub
Hack, crud! You beat me to it. I just re-discovered the same thing.
For Psyke1. I still don't see the advantage of building a function/sub to create a new instance of a form. I have no idea what that sub/function will do with the created form, but if it adds controls, modifies form properties, I think this would be more intuitive (code-wise) and less involved
But your project, your call. Don't forget to add error trapping in case the passed form name is not part of the project.Code:Dim f As Form
Set f = New Form1
' now call a sub and pass f so that new controls can be added or properties changed
You will be required to add in some sort of error checking process, that is built into your COM Project...
Try making it look, like this:
Code:On Error Goto ...........