Page 1 of 1
Macro to close forms and OpenOffice.org
Posted: Fri Mar 20, 2009 12:48 pm
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
Re: Macro to close forms and OpenOffice
Posted: Sat Mar 21, 2009 2:09 pm
by Hardy
Don't know what you mean by close form (a form is no graphic object).
As for the app try ThisComponent.Close()
Re: Macro to close forms and OpenOffice
Posted: Tue Mar 24, 2009 9:59 am
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
Re: Macro to close forms and OpenOffice
Posted: Tue Mar 24, 2009 3:47 pm
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?
Re: Macro to close forms and OpenOffice
Posted: Tue Mar 24, 2009 10:17 pm
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.
Re: Macro to close forms and OpenOffice
Posted: Thu Mar 26, 2009 8:40 am
by Hardy
Haven't you tried ThisComponent.Close() as suggested above? This closes the OOo suite in my applications.
Re: Macro to close forms and OpenOffice
Posted: Thu Jan 21, 2010 5:14 pm
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
Re: Macro to close forms and OpenOffice
Posted: Thu Jan 21, 2010 10:01 pm
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
Re: Macro to close forms and OpenOffice
Posted: Fri Jan 22, 2010 11:09 am
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.
Re: Macro to close forms and OpenOffice
Posted: Fri Jan 22, 2010 11:36 am
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
Re: Macro to close forms and OpenOffice
Posted: Fri Jan 22, 2010 12:35 pm
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:
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.
Re: Macro to close forms and OpenOffice
Posted: Fri Jan 22, 2010 10:22 pm
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