How to set close form button?

I would liek to add a button that opens a new form while closing the current form.
I have this macro:

Sub openDEMOFORM
	const sNewDocumentName="demoForm"
	oNewFormDocument=ThisDatabaseDocument.FormDocuments.getbyname(sNewDocumentName).open
	oForm.parent.parent.CurrentController.Frame.close(True)
End Sub

where the oForm.parent.parent.CurrentController.Frame.close(True) comes from this post.

What would be the correct syntax?

Thank you

Why don’t you set

ThisDatabaseDocument.FormDocuments.getbyname(sOldDocumentName).close

You could get the name of the old form directly in the procedure with

aFormStart() = Split(thisComponent.Title, thisComponent.UntitledPrefix)
ThisDatabaseDocument.FormDocuments.getByName( Trim(aFormStart(1)) ).close

this gives me an error:

So: What is the name of the form document. You have written sOldDocumentName, but this is a variable.

1 Like

Thanks, it worked. Is there a way also to automatically save the data avoiding the pop up window?

Believe me. You don’t really want that.

Draw a button.
Action: Open Document or URL
URL: .uno:CloseDoc

I don’t think I can add URL directly, because execute action is already taken by running a macro (opening the other form):


can I add .uno:CloseDoc to the macro?

Whatever you try to do at this stage, macros are not the solution as far as I can see in your other current topic. Macros are a horrible waste of time when your database is not ready and the forms are poorly designed.