Macro to close forms and OpenOffice.org

Discuss the database features
Post Reply
joaofmateus
Posts: 33
Joined: Fri Mar 20, 2009 12:15 pm
Location: Lisbon - Portugal

Macro to close forms and OpenOffice.org

Post by joaofmateus »

I am novice on Base (where it came from ACCESS and scheduled) and would like to develop an application already with some difficulty, but fought against the wall when trying to create a macro to close a forms forms and other to close OpenOffice.

For the forms used in the net I found this:

Code: Select all

Sub Close_Forms

       Dim oForm As Object

       Rem... This component hack
       oForm = thisComponent.Parent.FormDocuments 
       if oForm.HasByName("fMAIN") then     
          oForm = oForm.getByName("fMAIN")
          if not IsNull(oForm.Component) then
            oForm = ThisComponent.Drawpage.Forms.getByName("fMAIN")
          End if
       Else
       msgbox "Form Not Found"
       End if

      oForm.parent.parent.CurrentController.Frame.close( true ) Rem... this way so dosen't close wrong form because of timing.
      'thisComponent.CurrentController.Frame.close( true ) Rem.. This line commented out. Could close wrong form if you clicked to another too quickly
     
 End Sub
For OpenOffice, use this:

Code: Select all

Sub CallTerminateOpen()

      stardesktop.terminate
       
 End Sub
Both have problems, and OpenOffice is hung.

I use Windows Vista Home Premium and OpenOficce 3.0.1

Does someone can give me a hand?

Advance grateful
OOo 4.1.5 on MS Windows 10
Hardy
Volunteer
Posts: 103
Joined: Thu Jan 29, 2009 2:50 pm

Re: Macro to close forms and OpenOffice

Post by Hardy »

Don't know what you mean by close form (a form is no graphic object).
As for the app try ThisComponent.Close()
OOo 3.0.X on Ms Windows W2k
gtv625
Posts: 18
Joined: Mon Dec 15, 2008 4:16 pm
Location: Kukljica, Croatia

Re: Macro to close forms and OpenOffice

Post by gtv625 »

for me the only method for the moment is to add a button to close the form and assign action Open document/web page and URL .uno:CloseDoc
OOo 3.0.X on Ms Windows XP
joaofmateus
Posts: 33
Joined: Fri Mar 20, 2009 12:15 pm
Location: Lisbon - Portugal

Re: Macro to close forms and OpenOffice

Post by joaofmateus »

Hello gtv625

The method has been suggested that, indeed, all who tested, which solved the problem of closing the forms, but I still have to close OpenOffice, which suggests?
OOo 4.1.5 on MS Windows 10
gtv625
Posts: 18
Joined: Mon Dec 15, 2008 4:16 pm
Location: Kukljica, Croatia

Re: Macro to close forms and OpenOffice

Post by gtv625 »

sorry i misread your post, i'm not sure that is possible to close OOo from BasicIDE macro because basic needs OOo to run this macro. another idea if fits your need is to use DB Doc Shortcuts extension created by R.Benitez that you can find on www.baseprogramming.com and than to put on first form one push button that can close this form.
OOo 3.0.X on Ms Windows XP
Hardy
Volunteer
Posts: 103
Joined: Thu Jan 29, 2009 2:50 pm

Re: Macro to close forms and OpenOffice

Post by Hardy »

Haven't you tried ThisComponent.Close() as suggested above? This closes the OOo suite in my applications.
OOo 3.0.X on Ms Windows W2k
gladtobegrey
Posts: 9
Joined: Thu Jan 21, 2010 5:01 pm

Re: Macro to close forms and OpenOffice

Post by gladtobegrey »

I have tried ThisComponent.Close() in my Base (HSQL) database, and get the error:
BASIC runtime error.
An exception ocurred
Type: com.sun.star.lang.illegalArgumentException
Message: arguments len differ!.
Apart from the observation that that is a really cr*ppy message, can anyone help me decipher it and work out what's wrong?

The macro 'closeThisDatabase' is invoked from a button on a 'menu' form, thus:

Code: Select all

Sub closeThisForm
	thisComponent.CurrentController.Frame.close( true )
End Sub

Sub closeDatabase
	closeThisForm
	thisComponent.Close()
End Sub
If I change it to :

Code: Select all

Sub closeDatabase
	closeThisForm
	thisComponent.Close( true )   OR  ... ( false )
End Sub
... then it does nothing. The currently active form closes, but the database window stays open.

Thanks
OpenOffice 3.1.1 Windows XP and Vista
RPG
Volunteer
Posts: 2261
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Macro to close forms and OpenOffice

Post by RPG »

Hallo

A form can be closed with a button.
use in the url then : .uno:CloseDoc

You can also use the next sub

Code: Select all

sub closeform(oEv as object)
dim sFormname2
sFormname2=right(thiscomponent.title,instr(thiscomponent.title,":")-2)
ThisDatabaseDocument.FormDocuments.getbyname(sFormname2).close
end sub
If you knew the name of the form then you can give only the name of the form in stead of the basic instruction for finding the name.
You have to know this method can only be used when you are working inside the same database and the form also belongs to that database. When you want close forms not in a database then you have to use other methods.

The thread is dated before you can use this easy method. In that time the method of closing a form changed sometimes.

Romke
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
gladtobegrey
Posts: 9
Joined: Thu Jan 21, 2010 5:01 pm

Re: Macro to close forms and OpenOffice

Post by gladtobegrey »

Romke, thanks for that - I found that your code returned "(read-only)" as the form name ... however it did point me in a useful direction.

I modified the code as follows:

Code: Select all

Sub closeThisForm (oEv as object)
	dim sFormName As String
	dim sTitle As String
	dim iStart As Integer
	Dim iLength As Integer
	Dim iEnd As Integer
	sTitle = ThisComponent.Title
	iStart = Instr(sTitle,":") + 2
	iEnd = Instr(sTitle,"(") - 1
	iLength = iEnd - iStart
	sFormName = Mid(sTitle, iStart, iLength)
	ThisDatabaseDocument.FormDocuments.getbyname(sFormName).close
End Sub
... which returns me the correct form name and closes it. This is a self-contained app - i.e. all the data, macros and forms are in the one database, so that's a good solution for me.

I still have the problem of how to close the whole App - i.e. my database AND the Base window - from a form control. Any suggestions how I can do that? ThisComponent.Close() - as suggested in the earlier thread - does not work. I want to make my application as user-friendly as possible for a completely non-technical end-user.

ThisDatabaseDocument.Close() ought to work, but see http://www.mail-archive.com/dba-bugs@op ... 33412.html issued on Jan 11th which reports that several OO executables are left running after the close.
Last edited by gladtobegrey on Fri Jan 22, 2010 12:31 pm, edited 2 times in total.
OpenOffice 3.1.1 Windows XP and Vista
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro to close forms and OpenOffice

Post by Villeroy »

You have to close the connection before you can close the document without crash.
Snippet recorded by http://extensions.services.openoffice.org/project/MRI
oInitialTarget is the active database document

Code: Select all

Sub Snippet( Optional oInitialTarget )
  Dim oCurrentController As Object
  Dim oActiveConnection As Object

  oCurrentController = oInitialTarget.CurrentController

  oActiveConnection = oCurrentController.ActiveConnection
  oActiveConnection.close()
  oInitialTarget.close( True )
End Sub
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
gladtobegrey
Posts: 9
Joined: Thu Jan 21, 2010 5:01 pm

Re: Macro to close forms and OpenOffice

Post by gladtobegrey »

Villeroy wrote: oInitialTarget is the active database document
Thanks, I've modfied the closeDatabase macro accordingly, and it seemed to work first time around, but subsequently I get the error "Object variable not set" reported against the line:

Code: Select all

oActiveConnection.close()
Modifying the code to:

Code: Select all

Sub closeDatabase
	Dim oConnection As Object
	closeThisForm  rem Sub to close the currently active form
        oConnection = ThisDatabaseDocument.CurrentController.ActiveConnection
	ThisDatabaseDocument.Close( true )

End Sub
... seems to work, but still leave soffice.bin, soffice.exe and sbase.exe running after the app closes (as reported in the link above). If I then re-open, and immediately close, the database, all three processes are then closed. I also notice that the autoexec macro to open the MENU form when the database is opended doesn't execute during this re-opening of the database, but does on subsequent openings.

This pattern seems to repeat reliably.
OpenOffice 3.1.1 Windows XP and Vista
RPG
Volunteer
Posts: 2261
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Macro to close forms and OpenOffice

Post by RPG »

Hello

When I used stardesktop.terminate
This is enough to close the stardesktop and the database and even asked me for storing new not finished input data.
When basic is open then the basic window is not closed

You have to store this macro in My macros and not in the database otherwise you can get an error. I don't know if it is save.

Romke
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
Post Reply