Macro to open form works in base but not in writer

I followed the advice on another thread to develop my forms not in base but in writer. For this I saved existing base-forms in .odt format.
My buttons call a macro to open a new form and close the present one. Works in base but in writer I get a error which I do not understand.

*Error> Basic runtime error, Object variable not set

My macro:
REM ***** BASIC *****

Option Explicit

Sub Open1
ThisDatabaseDocument.FormDocuments.getbyname(“StandardObjects”).open
End Sub

Sub Open2( oEv as variant )
'reads sOpenFormName & sCloseFormName separated by a comma from tag of calling button
Dim N1 as Integer
Dim N2 as Integer
Dim xpos as Integer
Dim ypos as Integer
Dim XX as String
Dim sOpenFormName as String
Dim sCloseFormName as String
Dim formsTC as Variant
Dim oConnection As Variant
Dim aProp(1) As New com.sun.star.beans.PropertyValue

XX=oEv.Source.Model.Tag ' get button's form from Additional information on button control
N1=len(XX)
N2=inStr(XX,",")
If N2<>0 Then
   sOpenFormName = left(XX,N2-1)
   sCloseFormName = right(XX,N1-N2)
Else
   sOpenFormName = XX
   sCloseFormName = ""
End If

**formsTC = thisComponent.Parent.getFormDocuments**
oConnection = thisComponent.Drawpage.Forms(0).ActiveConnection
aProp(0).Name = "ActiveConnection"
aProp(0).Value = oConnection
aProp(1).Name = "OpenMode"
aProp(1).Value = "open"

If sOpenFormName <> "" Then formsTC.loadComponentFromURL(sOpenFormName, "_blank", 0, aProp()) 
If sCloseFormName <> "" Then ThisDatabaseDocument.FormDocuments.GetByName(sCloseFormName).close

End Sub
*
The form to be opened is named in “Control-Properties - General - Additional Information” as AM_StaffList,AA_Startpage. Seperated by comma.
My guess is that it has something to do with the way the forms are saved as freestanding writer=documents rather than within the base-structure.

in Base Objet ThisDatabaseDocument
in Writer ThisComponent Object

Never expected such a inconsistency. Took your advice and changed as suggested.
Sub Open1
ThisComponent Object.FormDocuments.getbyname(“StandardObjects”).open
End Sub

But now I get a different error:
Symbol thisComponent already defined differently
the error seem to occur on the line
formsTC = thisComponent.Parent.getFormDocuments
oConnection = thisComponent.Drawpage.Forms(0).ActiveConnection

Internal forms could be found without any problem with ThisDatabaseDocument.
For opening external form you will need the URL of this forms. So sOpenFormName should contain a URL, set by ConvertToUrl to a URL which could be found by the system. Then
StarDesktop.loadComponentFromUrl(sOpenFormName, "_blank", 0, Arg())
will work.

Could you upload the document (and database file) and indicate the order of actions that lead to the error?

When you want work with macro’s to open formdocuments then you must first have an idea about what you want do. Your first must have an idea want you work with a databasedocument in which are all your formdocuments, reports , tables and queries. Then I sea this combination more as an applications. That means also it can be important to have more databasedocuments for one database, you can not work with an embedded database in this way.

When you follow that idea then you have also to open your databasedocument first. The reason for this is you need the controller of your databasedocument. It wil be also easy when you store all your macro’s in your databasedocument

Now you can work with
thisdatabasedocument.currentcontroller.loadcomponent(objecttype,objectname,boolean for edit)

You can call this macro on the same way as your examples

objecttype
0 for table
1 for query
2 for form
3 for report

Objectname = is a hierarchical name as string

The macro “ThisDatabaseDocument.FormDocuments.loadcomponentfromURL and more” is so difficult there it is possible to open a formdocument which is an other databasedocument and I have the idea there no need to have a controller for the databasedocument.