Hello,
It would be nice to show (or at least provide a link to) code you state that you have tried. The example you show is meaningless and doesn’t make any sense on its own.
There is a routine in my answer in this post → Base ERROR - Open Form with macro.
You can then use this sub:
Sub OpenBonsai
FormChange("Bonsai Database")
End Sub
(terrible form name) attached to the push button Execute action
event to open the form.
The routine also has optional code you can remove comments on which will close the existing form.
Edit:
Had already mentioned the code in the link had the info to close a form. Here is a routine for just the closing:
SUB FormClose( sFormName )
Dim ObjTypeWhat
Dim ObjName As String
ObjName = sFormName
ObjTypeWhat = com.sun.star.sdb.application.DatabaseObject.FORM
If ThisDatabaseDocument.FormDocuments.hasbyname(ObjName) Then 'Check the form exists'
ThisDatabaseDocument.FormDocuments.getbyname(ObjName).close
Else
MsgBox "Error! Wrong form name used. "+chr(10)+"Form Name = " & ObjName
End if
End Sub
and call that routine the same as the open using:
Sub CloseBonsai
FormCLose("Bonsai Database")
End Sub