[Solved] Close Form after pressing button

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
DreamerArgentino
Posts: 17
Joined: Sun May 20, 2018 12:02 am

[Solved] Close Form after pressing button

Post by DreamerArgentino »

Hi all.
I have this code to open a Form from a switchboard, and I would like to press it, execute two actions, the current one and also close the switchboard.

I hope you can help me. Thank you!
------------------------------------------------------------------------------------------------------------------------------------

Code: Select all

REM  *****  BASIC  *****

Sub OpenForm1 (oEvent as object)

const sNewDocumentName="FRM-Students01"     '"FRM-Students"

'If Not Globalscope.BasicLibraries.isLibraryLoaded("MRILib") Then
'      Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
'End If
'Dim oMRI as object
'oMRI = CreateUnoService( "mytools.Mri" )


oDoc = ThisDatabaseDocument
'oMRI.inspect oEvent
oForm = oEvent.Source.Model.Parent  'get form from event 
'oMRI.inspect oForm
oForm.updateRow  'save selection

oNewFormDocument=oDoc.FormDocuments.getbyname(sNewDocumentName).open
End Sub

Sub Macro1

End Sub
Last edited by robleyd on Wed Dec 05, 2018 12:52 am, edited 2 times in total.
Reason: Added Code tags
OpenOffice 4.1.5 On Windows 10
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Close Form after pressing button

Post by UnklDonald418 »

To close the switchboard you can add a line to your macro

Code: Select all

oDoc.FormDocuments.getbyname("Initial-Switchboard").close
however, because you have made changes to the form document by making a selection you will get a dialog asking if you want to save your changes.
To avoid the dialog you can use:

Code: Select all

oDoc.FormDocuments.getbyname("Initial-Switchboard").dispose
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
DreamerArgentino
Posts: 17
Joined: Sun May 20, 2018 12:02 am

Re: Close Form after pressing button

Post by DreamerArgentino »

Excellent!!! Thank you UnklDonald418!!!
OpenOffice 4.1.5 On Windows 10
Post Reply