Datenbank per Makro schliessen

Programmierung unter AOO/LO (StarBasic, Python, Java, ...)

Moderator: Moderatoren

WSO
*****
Beiträge: 233
Registriert: Di, 22.04.2014 13:03

Datenbank per Makro schliessen

Beitrag von WSO »

Hallo Zusammen,
ich habe mir aus verschiedenen (älteren) Threads (Version 3)eine Lösung zusammenkopiert, die leider nicht läuft.
Beim Start der Datenbank kommt eine unqualifizierte Fehlermeldung: "Basic Fehler". Der Cursor steht auf dem ersten
DIM-Statement.
Kann mir bitte jemand helfen das unter LO 4.2 (WIN 7, Linux) zum laufen zu bringen.
Ist doch ein nettes feature ...

Code: Alles auswählen

SUB Close_DB_Form (oEvent AS OBJECT)
	'an das Startformular (Dokument schliessen) gebunden

   DIM oDoc AS OBJECT
   	DIM oDispatch AS OBJECT
   
   	if isClosed() = true then
      	   exit Sub
   	end if
            
   	ThisComponent.Parent.store

   oDoc = ThisComponent.CurrentController.Frame
   oDispatch = createUnoService("com.sun.star.frame.DispatchHelper")
   oDispatch.executeDispatch(oDoc, ".uno:CloseDoc", "", 0, Array()) ' das aktive Formular schließen

   	oDoc = ThisComponent.Parent.CurrentController.Frame
   	oDispatch = createUnoService("com.sun.star.frame.DispatchHelper")
   	oDispatch.executeDispatch(oDoc, ".uno:CloseDoc", "", 0, Array())

   IF CountAllForms() = 0 then ' kein externes Fenster offen
   	 oDispatch.executeDispatch(oDoc, ".uno:CloseWin", "", 0, Array())
   end if

   	oDispatch.executeDispatch(oDoc, ".uno:CloseWin", "", 0, Array())
   
End SUB


Function CountAllForms 
	' alle offenen Fenster (calc, ...) zählen, nachdem die Anwendung selbst beendet ist - also nach "uno:closeDoc"
	
GlobalScope.BasicLibraries.LoadLibrary("Tools")
Dim oDocs As Object, oDoc As Object, oComponents As Object, oDispatch As Object, i As Integer
i = 0
oComponents = StarDesktop.getComponents()
oDocs = oComponents.createEnumeration()
DO WHILE oDocs.hasMoreElements()
  	ON ERROR resume next
	oDoc = oDocs.nextElement()
	i = i + 1
	' msgbox oDoc.title
	LOOP
	CountAllForms = i
End Function


Function isClosed() As Boolean
   isClosed = glbClosed      'Globale Variable
End Function


Function setClosed(bClosed)
   glbClosed = bClosed
End Function