There are some errors in your code. Here are some fixes.
The Form:
Option Explicit
Private Sub Command1_Click()
Dim oWinObj As New WindowObj
Dim oForm As Form
Set oWinObj = New WindowObj
Set oForm = oWinObj.OpenForm("Form2")
End Sub
Private Sub Command2_Click()
Dim oWinObj As New WindowObj
Set oWinObj = New WindowObj
oWinObj.OpenForm "Form2"
End Sub
The Class:
Option Explicit
Public Function OpenForm(sFormName As String) As Form
Dim oForm As Form
Set oForm = Forms.Add(sFormName)
oForm.Show
Set OpenForm = oForm
End Function
Public Sub OpenFormSub(sFormName As String)
Dim oForm As Form
Set oForm = Forms.Add(sFormName)
oForm.Show
End Sub
>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?
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com