General information
Category:
Coding, syntax & commands
Forms.add doesn't return an object, you'll need to loop through
the forms collection after adding it and you'll be all set:
Dim sForm As String
sForm = "Form1"
VB.Forms.Add sForm
For Each oForm In VB.Forms
If oForm.Name = sForm Then
oForm.Show
End If
Next oForm
>I want to open a form by passing the name of the form as a string
>to a function. I have:
>
>
>Public Sub LaunchForm(sFormName As String)
>
> Dim oWinObj As New WindowObj
> Dim oForm As Form
>
> Set oWinObj = New WindowObj
>
> oForm = oWinObj.OpenForm(sFormName)
>
>End Sub
>
>
>oWinObj is in a class:
>
>
>Public Function OpenForm(sFormName As String) As Form
>
> Dim oForm As Form
>
> Set oForm = Forms.Add(sFormName)
> oForm.Show
>
> OpenForm = oForm
>
>End Function
>
>
>Now it I don't try to return the instance of the form (oForm), it
>works fine. In other words, if the function above is defined as
>a Sub instead of a Function.
>
>I get the error 'Invalid use of property'
>
>Can someone help please?
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only