ScriptForge Database Demo

Without trying to be offensive, that’s a disingenuous comment (see Villeroy’s post quoted below for what’s involved) if using dispatch commands is a weak method of creating macros.

Executing from a button on a form in a base document it’s returning an error.

One Line:

ThisDatabaseDocument.FormDocuments.getbyname( "FORM_NAME" ).close
1 Like

This seems to work actually. Thanks to @flywire

Close a form document, no matter where the code is stored, no matter if the form is embedded or not.
getParentObject finds the containing office document. If that document is embedded, closeEmbeddedFormDocument lets the embedding database document closes the form document. An embedded form needs to be closed by the containing database document, otherwise you get a veto exception.

Sub closeFormDoc(ev)
'mri = createUnoService("mytools.Mri")
doc = getParentObject(ev.Source.Model, "com.sun.star.document.OfficeDocument")
'mri.inspect( doc)
if not (doc.Parent Is Nothing) Then
	closeEmbeddedFormDocument doc.getParent(), doc.getTitle()
else
	 doc.close(False)
endif
End Sub

Function getParentObject(byval m, srvName$)
do until m.supportsService(srvName)
	m = m.getParent()
loop
getParentObject = m
End Function

Sub closeEmbeddedFormDocument(odb, sTitle)
	forms = odb.FormDocuments
	for i = 0 to forms.getCount() -1
		form = forms.getByIndex(i)
		comp = form.getComponent()
		if not isnull(comp) then
			if comp.Title = sTitle then 
				form.close()
				exit for
			endif
		endif
	next i
End Sub
2 Likes

@Villeroy
Only briefly tested but looks promising.
.
Correct me if I a incorrect but it appears this has nothing to do with ScriptForge.
.
Edit:
.
Have already added an optional parameter to send title of a different form to close. Placed your routines in My Macros. Works but will need some error processing.
.
Very interesting possibilities.
.
Edit 2:
After more thought, although interesting and to be kept for future reference, other methods are done with way less code.

LibreOffice Macros > Access2Base is for Base.

The question is in regard to the ScriptForge library.