How to close a form by index or variable?

WIN10,LO7.7.7.3,Hsql2.51

Hi,

Looking for a way to make a custom navigation bar work.

soffice.bin_k5yQv9yKgc

This bar will be present on multiple forms with each button opening one of the other forms and closing the calling form. There also is one form which will never close being overlaid with the others.

Now since a button does not know on which form it is, how can I close this form since a tag is not useful in this case.(Unless creating lots of macros)

Now is it possible to close a form by its index? If so – how? Another thought would be to assign a variable to the form on form opening, however I have not found a way yet to substitute the form name somehow like

`
Sub KillUtil
’ fid = “frmUtil”
ThisDatabaseDocument.FormDocuments.getbyname.(fid).close
End Sub``

Thank you for your help

Hello,
Been using this for years:

	sTitle = ThisComponent.Title
	sName = Mid(sTitle, Instr(sTitle,":") + 2)
	ThisDatabaseDocument.FormDocuments.getbyname( sName ).close

Thanks, does this mean I first need to close and then open the new form ?

No. Just tested OK.

If doing so, first save:

save_me = ThisDatabaseDocument.FormDocuments.getbyname( sName )

Then you can close whenever:

save_me.close()
1 Like

Thanks, that’s fantastic !

I don’t know if this can be useful to you, but I’m going to share it with you.
I use this macro in Basic to open a form and close one from the event link to the button, I generally choose the event [Accept action].

Here is the macro:

Sub OpenCloseForm
     const FormToOpen ="NameOfTheForm" 'Form to open
     HLink=ThisDatabaseDocument.FormDocuments.getByName(FormToOpen).open

     const FormToClose ="NameOfTheForm" 'Form to close
     HLink=ThisDatabaseDocument.FormDocuments.getByName(FormToClose).close
End Sub

Thank you Rene.