[Solved] Cancel event, [Impossible] Cancel close document

Creating and using forms
Post Reply
ponlerd
Posts: 56
Joined: Sun Nov 15, 2009 6:22 pm
Location: Bangkok, Thailand

[Solved] Cancel event, [Impossible] Cancel close document

Post by ponlerd »

Hi all: I have been searching for hours and not finding an answer(so exhausted)
,
Is it possible to prevent the form from closing in BASIC??

This link is the closest thing that i found
http://www.oooforum.org/forum/viewtopic.phtml?t=22353

Code: Select all

Global oListener as Object

Sub install_listener
oListener = CreateUnoListener("Listensub_", "com.sun.star.util.XCloseListener")
thisComponent.addCloseListener(oListener)
End Sub

Sub Listensub_disposing(oEvent)
msgbox("disposing")
End Sub

Sub Listensub_queryClosing(oEvent, bOwnership)
msgbox("query")
End Sub

Sub Listensub_notifyClosing(oEvent)
msgbox("notify")
End Sub 
Adds a CloseListener, in the api
http://api.openoffice.org/docs/common/r ... tener.html
says that

Such close events are broadcasted by a XCloseBroadcaster if somewhere tries to close it by calling XCloseable::close(). Listener can:

* break that by throwing CloseVetoException
* or accept that by deregister himself at this broadcaster.

No idea what "throws" mean
searching for hours, i'm afraid that it really cannot be done in basic (a lot of code that i searched for has try, catch, ...)

Actually , in BASIC is it possible to cancel all events,
like the event "Before record action", if it is not possible to cancel it, then what would be the difference if the macro is attached "After record action", because even if you don't want the "record action" to happen, you don't have any ways of cancelling it.
I don't want to believe that it can't be done...........I'm open to all methods, even it means that i have write something that is not BASIC, i really want to use this openoffice!!

(again in ms access, one can cancel a "before" event easily by typing Cancel=True)

Title Edited. A descriptive title for posts helps others who are searching for solutions and increases your chances of a reply. (TheGurkha, Moderator)
Last edited by ponlerd on Sun Apr 04, 2010 4:40 am, edited 3 times in total.
OOo 3.2 Ubuntu 9.04 / OOo 3.2 Windows7 / Migrating from Access
RPG
Volunteer
Posts: 2261
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Possible to prevent Form or document from closing?

Post by RPG »

Hello


For me your post is not so clear. There you talk about a form as document and as a form as you see in the form navigator.

A form as you see in the form navigator.
You can cancel the action : "Before record action",

From the help file
Before update
The Before update event occurs before the control content changed by the user is written into the data source. The linked macro can, for example, prevent this action by returning "FALSE"
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
ponlerd
Posts: 56
Joined: Sun Nov 15, 2009 6:22 pm
Location: Bangkok, Thailand

Re: Possible to prevent Form or document from closing?

Post by ponlerd »

Hi RPG, thank you for your reply
i studied the Before update in the help before, but couldn't get it to work.
Could you show a working example of how to set things up?

I tried before is
Function Beforeupdate (Event as Object) as Boolean
If ........ Then
Beforeupdate = False
Else
Beforeupdate = True
End if
end function

But it doesn't stop the updating process at all.
OOo 3.2 Ubuntu 9.04 / OOo 3.2 Windows7 / Migrating from Access
RPG
Volunteer
Posts: 2261
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Possible to prevent Form or document from closing?

Post by RPG »

Hello

You make not clear on this moment if you are talking about a form as document or as a form as you see in the form navigator. This acts only on a form as you see in the form navigator.
Also you have to understand it acts only on one form in your document and not all forms.

I did tel about update but that action is for a field not not for a form. I Have copy a new part. But baasicly it doeas not change about what I told.
I did read that there are some problems with OOo3.2 But I don't have that problem but this can maybe also a reason it is not working for you.
I have OOo 3.2.0.7
OOo 320 m21buid 9319

I hope this help you
Before record action
The Before record action event occurs before the current record is changed. For example, the linked macro can request confirmation in a dialog.

Code: Select all

function testBeforeRecordAction(oEvent as object)
testBeforeRecordAction=false
end function
Romke
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
ponlerd
Posts: 56
Joined: Sun Nov 15, 2009 6:22 pm
Location: Bangkok, Thailand

Re: Possible to prevent Form or document from closing?

Post by ponlerd »

Thank you Romke, I tried the code and it worked! Thank you! Actually, I really don't understand why i couldn't do it, since it's so easy, and it's very much like VBA.

Ok, now the problem about before .... events is solved and out of the way.

Now I'm starting to understand why you keep asking whether i want to prevent closing the form(dialog) or form(document)

Ok, I want to prevent closing the document.
I opend the form in design mode, then
Tools>customize> attach a macro at the "Document is going to be closed" event.

Code: Select all

Function testdocclosing (oEvent as object)
Form = ThisComponent.DrawPage.Forms.getByIndex(0)
If Form.Columns.getByName("ProductCode").String = 10 Then
msgbox "you cannot close because code = 10"
testdocclosing=false
Else
msgbox "code is not  10 so ok to close"
testdocclosing=true
end if
end function
When I click the X button to close the form, the macro fires, but no matter what the condition is, the document closes anyway.

Am i doing something wrong??
Or I have to go to the XCloselistener and the stuff that I really don't understand....

Thank you so much for all the help
OOo 3.2 Ubuntu 9.04 / OOo 3.2 Windows7 / Migrating from Access
RPG
Volunteer
Posts: 2261
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: [HalfSolved]How to cancel event and cancel closing docum

Post by RPG »

Hello

I did point only to the form as you see in the form navigator there ms777 has fully answered the other part. As far I know it is not possible. But I have little knowledge about that part but ms777 has more knowledge about that and I believe him and that was for me enough to answer only about a form as you see in the form navigator.

I have seen this question more and never seen an answer that I remember
Maybe you can start a thread on the macro part of the forum or bump the question you already did found.

I knew it is always difficult to learn an other environment.

Romke
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
ponlerd
Posts: 56
Joined: Sun Nov 15, 2009 6:22 pm
Location: Bangkok, Thailand

Re: [Half Solved] Cancel event and cancel closing document

Post by ponlerd »

I see, i'm quite new around here, but once you mentioned ms777, i went back to take a look and see that he is a superuser. I guess i have to believe him also.
Thanks for the form on navigator part again, I'll try to see if there is any workaround to do my task.
Cheers!
OOo 3.2 Ubuntu 9.04 / OOo 3.2 Windows7 / Migrating from Access
ponlerd
Posts: 56
Joined: Sun Nov 15, 2009 6:22 pm
Location: Bangkok, Thailand

Re: [Solved] Cancel event, [Impossible]cancel closing docume

Post by ponlerd »

Finally, this is what i did
I want to prevent closing the form(document) because I'm afraid that someone will close the form(document) before the form(navigator) is updated (with validation)
Everytime a user updates data in a form, or inserts a new record, if the user does not click save or go to the next record, but clicks the close button
Base will have a confirmation message whether the user wants to Save the data, Not save the data, or cancel the closing.
I guess Base already had this mechanism of cancelling the closing of the form in place.
Now if the user clicks Save, (or yes in that message box),
The before record action fires
Then after record action fires
then the document is closed.
So what i am doing is i just put the form validation or whatever i want to check , attach it with the before record action event.
If the before record action = False then the data will not be updated, and the closing process will not continue.
This is ok for me, because now i'm sure that the user will not click close and save any unvalidated data into the table.
Again this was possible because of your example, Romke.Thanks!
OOo 3.2 Ubuntu 9.04 / OOo 3.2 Windows7 / Migrating from Access
Post Reply