Page 1 of 1
[Solved] Can buttons open and close forms?
Posted: Fri Apr 24, 2009 10:56 am
by lankymjc
I am trying to use two different buttons in my forms; one to open another form, and one to close it. But i can't figure out how to do it! there are plenty of preset actions, but none of them open and close forms.
Re: Can buttons open and close forms?
Posted: Fri Apr 24, 2009 11:35 am
by Villeroy
[Solved] Closing form with macro
Use property "Additional Info" to specify the name of the form to open.
Assign this macro to the button's event "Before Commencing":
Code: Select all
Sub openFormByTag(oEv)
REM OOo3.0: Reads the form name from a calling control's tag
cWhat = com.sun.star.sdb.application.DatabaseObject.FORM
oModel = oEv.Source.getModel()
sName = oModel.Tag
oView = oModel.Parent.Parent.Parent.Parent.getCurrentController()
oView.loadComponent(cWhat, sName, FALSE)
End Sub
The button must belong to a top-level form rather than a subform.
Re: Can buttons open and close forms?
Posted: Fri Apr 24, 2009 5:12 pm
by lankymjc
Where do I put the macro? I can't find where to write it into
Re: Can buttons open and close forms?
Posted: Fri Apr 24, 2009 5:38 pm
by Villeroy
[Tutorial] How to install a code snippet
Next version 3.1 will allow for macros embedded in database documents. Since this macro is designed to work with any embedded form, you may prefer the global container.
Re: Can buttons open and close forms?
Posted: Fri Apr 24, 2009 6:04 pm
by lankymjc
I can get it to open another form on demand, but I still can't get it to close it; that link you gave me wasn't particularly helpful (little ole me just got confused!)
Re: Can buttons open and close forms?
Posted: Fri Apr 24, 2009 6:16 pm
by Villeroy
You can use a button to open a URL such as
http://google.com or file:///tmp/document.odt
Most office commands have URLs too. One of them is
.uno:CloseDoc which corresponds to menu:File>Close
Re: Can buttons open and close forms?
Posted: Fri Apr 24, 2009 8:45 pm
by lankymjc
Where do i type that in?
Re: Can buttons open and close forms?
Posted: Fri Apr 24, 2009 9:03 pm
by Villeroy
Button properties
Action: Load document or web page
URL: .uno:CloseDoc
or call menu:Insert>Hyperlink...
Re: [Solved] Can buttons open and close forms?
Posted: Thu May 14, 2009 9:13 pm
by coolmike
Thanks
This helped me a lot.
Can you use buttons to generate reports as well? If so, how would the macro need to be changed?
Thanks again.
Re: [Solved] Can buttons open and close forms?
Posted: Thu May 14, 2009 9:37 pm
by Villeroy
When I change ...
Code: Select all
cWhat = com.sun.star.sdb.application.DatabaseObject.FORM
... to ...
Code: Select all
cWhat = com.sun.star.sdb.application.DatabaseObject.REPORT
... the office freezes. It's one of hundreds of bugs in the database API.
Do you know the switchboard extension? Obviously it contains working code to open a report. I don't waste more time with this branch of the API, particularly not for gimmicks like loading a report with one click.
Re: [Solved] Can buttons open and close forms?
Posted: Sun Jul 12, 2009 5:30 pm
by JensOnOOo
Hi Villeroy,
you helped me also a lot with that macro, too,....many thanks,
Next questions:
How can i transfer data with that macro?
Example: When I have data "Green Monster" in form A, than I want that the data of "Green Monster" also appears in the next form B ... so that I can go on working easily....
I tried different possiblities, but nothing works out... (post/get ... etc)
Jens
Re: [Solved] Can buttons open and close forms?
Posted: Sun Jul 12, 2009 8:57 pm
by Villeroy
Normally you would use a subform attached to the same form document.
Re: Can buttons open and close forms?
Posted: Wed Dec 14, 2011 5:10 am
by ChristyMcFadden
Villeroy wrote:[Solved] Closing form with macro
Use property "Additional Info" to specify the name of the form to open.
Assign this macro to the button's event "Before Commencing":
Code: Select all
Sub openFormByTag(oEv)
REM OOo3.0: Reads the form name from a calling control's tag
cWhat = com.sun.star.sdb.application.DatabaseObject.FORM
oModel = oEv.Source.getModel()
sName = oModel.Tag
oView = oModel.Parent.Parent.Parent.Parent.getCurrentController()
oView.loadComponent(cWhat, sName, FALSE)
End Sub
The button must belong to a top-level form rather than a subform.
This macro helped me open a form, but can it be modified to open a specific record within a form? Thanks in advance.
Re: Can buttons open and close forms?
Posted: Fri Dec 16, 2011 7:48 pm
by DACM