# Form Button to close Form not working

Simple Base Form with just a Button, nothing else. Button click runs the Macro below which should close the form.

Sub CloseForm(oEvent)
oForm = oEvent.Source.Model.Parent
MsgBox oForm.Name
oForm.close
End Sub


The message box displays the correct Form name but the Form does not close and remains active and the Button can be clicked repeatedly. There are no Basic errors. Tried also close() and close(True) with same results. Xray shows that close is a valid method for the Form. Why does it not work?

edit retag close merge delete

Sort by » oldest newest most voted

Don't know what if anything that actually does. However, at that point you are working with the internal form & name not the document name which is needed for closing. You need to close at this level:

ThisDatabaseDocument.FormDocuments.getbyname( EXTERNAL_FORM_NAME ).close

more

I found this answer on OpenOffice Forum. This code works -

oForm.parent.parent.CurrentController.Frame.close(True)


The Form is being closed through the Form Document. @Ratslinger showed this using -

ThisDatabaseDocument.FormDocuments.getbyname( EXTERNAL_FORM_NAME ).close


As he said it is using the Document name and not the Form Name, this being the Name that the form is saved as and that appears in the Forms tab of the GUI. I don't understand why the Form Name does not work as close is a method for a Form.
An alternative is to use the Button property Button Action, set to "Open document/web page", and the URL to ".uno:CloseDoc". This can also be used if a hyperlink is inserted in the Form with the same URL.

more

Even if XRay or MRI show a method or setting, it doesn't mean it actually does something. Have run across dozens of such already. Always disliked the use of the term Form to represent multiple things. First is the Base Form or document. This has an open & close function. Now you also have the internal Form for the Form which contains controls and can have sub-forms etc. Additionally you can have many internal forms.

( 2018-03-01 03:50:15 +0100 )edit

And each of these internal forms can have their own subforms etc. I currently have a Base form with four internal forms and also a subform. Now with all this, there is never a need to 'open' an internal form which also means there is no need to 'close' an internal form. I you have four internal forms and you close one, what would happen to the other three? So accessing an internal form (as your oEvent) has nothing to do with the Form document your are attempting to close.

( 2018-03-01 03:57:06 +0100 )edit

## Stats

Asked: 2018-02-27 12:52:50 +0100

Seen: 1,181 times

Last updated: Feb 28 '18