[Solved] Can buttons open and close forms?

Creating and using forms
Post Reply
lankymjc
Posts: 14
Joined: Mon Apr 13, 2009 10:50 am

[Solved] Can buttons open and close forms?

Post 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.
Last edited by lankymjc on Sat Apr 25, 2009 5:20 pm, edited 3 times in total.
OOo 3.0.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can buttons open and close forms?

Post 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.
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
lankymjc
Posts: 14
Joined: Mon Apr 13, 2009 10:50 am

Re: Can buttons open and close forms?

Post by lankymjc »

Where do I put the macro? I can't find where to write it into
OOo 3.0.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can buttons open and close forms?

Post 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.
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
lankymjc
Posts: 14
Joined: Mon Apr 13, 2009 10:50 am

Re: Can buttons open and close forms?

Post 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!)
OOo 3.0.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can buttons open and close forms?

Post 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
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
lankymjc
Posts: 14
Joined: Mon Apr 13, 2009 10:50 am

Re: Can buttons open and close forms?

Post by lankymjc »

Where do i type that in?
OOo 3.0.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Can buttons open and close forms?

Post by Villeroy »

Button properties
Action: Load document or web page
URL: .uno:CloseDoc

or call menu:Insert>Hyperlink...
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
coolmike
Posts: 11
Joined: Thu May 14, 2009 6:27 pm

Re: [Solved] Can buttons open and close forms?

Post 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.
OOo 3.0.X on Ubuntu 8.x + WinXP
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Can buttons open and close forms?

Post 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.
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
JensOnOOo
Posts: 6
Joined: Sun Jun 21, 2009 5:58 pm
Location: India

Re: [Solved] Can buttons open and close forms?

Post by JensOnOOo »

Hi Villeroy,

you helped me also a lot with that macro, too,....many thanks, :D

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
OOo 3.1.X on MS Windows Vista
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Can buttons open and close forms?

Post by Villeroy »

Normally you would use a subform attached to the same form document.
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
ChristyMcFadden
Posts: 3
Joined: Thu Dec 01, 2011 10:59 pm

Re: Can buttons open and close forms?

Post 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.
Open Office version 3.3 on Windows 7
User avatar
DACM
Volunteer
Posts: 1138
Joined: Tue Nov 03, 2009 7:24 am

Re: Can buttons open and close forms?

Post by DACM »

ChristyMcFadden wrote:...can it be modified to open a specific record within a form?
Yes.

See the following:
Open a Form filtered
RPG's Tutorial: Open Form with Macros
Some problems can crop up if you use the Open Document event
...
AOO 4.1.x; LO 4.2.x; Windows 7/8 64-bit
Warning: Avoid embedded databases --> Solution: Adopt a portable 'split database' folder
Soli Deo gloria
Post Reply