[Solved] Opening a form with a button

Discuss the database features
Post Reply
RobynsEgg
Posts: 6
Joined: Mon May 25, 2015 12:16 pm

[Solved] Opening a form with a button

Post by RobynsEgg »

I've been reading the forums extensively, trying to figure out how to open a form from within a (different) form. I think I should use a button, and I think the correct way to do it is under the Action heading with .uno:open (though I would use a macro if that would do it too.) However, trying to find the correct syntax for it (or learning the .uno framework at all, actually) has been an exercise in futility?

UPDATE: many useful examples in here. Turned out not to be a coding issue at all but a button (Form) issue...
Last edited by RobynsEgg on Mon Feb 01, 2016 11:36 am, edited 3 times in total.
Robyn ~~~'~,~<@
OOffice 4.1.2 Win 8.1
User avatar
Villeroy
Volunteer
Posts: 31324
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Opening a form with a button

Post by Villeroy »

No such URLs for embedded documents. Since 11 years this is a missing feature. Get your forms out of the Base jail, use the switchboard extension or your own macro program.
[Tutorial] Standalone Forms / Switchboard
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
User avatar
MTP
Volunteer
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: Opening a form with a button

Post by MTP »

The macro syntax in StarBasic to open an embedded form document from a different embedded form document is

Code: Select all

ThisDatabaseDocument.FormDocuments.getbyname("NewDocumentName").open
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
RobynsEgg
Posts: 6
Joined: Mon May 25, 2015 12:16 pm

Re: Opening a form with a button

Post by RobynsEgg »

I have tried using

Code: Select all

sub openfrmTrack
ThisDatabaseDocument.FormDocuments.getbyname("frmTrackAdd").open

End Sub
which returned nothing. No errors, it just didn't do anything.

Then I tried using this (which I adapted from another forum topic)

Code: Select all

REM *****Open Contact Data Form*****
Sub OpenContactForm
Dim sNewDocumentName as string
sNewDocumentName="frmTrackadd"
oNewDoc = ThisDatabaseDocument.FormDocuments.getbyname(sNewDocumentName).open
oNewDoc.DrawPage.Forms.GetByIndex(0)
End Sub
Which got the same result. What am I missing?
Robyn ~~~'~,~<@
OOffice 4.1.2 Win 8.1
User avatar
RoryOF
Moderator
Posts: 34787
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Opening a form with a button

Post by RoryOF »

When posting code, please use PostReply or FullEditor windows and use the Code button. This makes it easier to read the code and makes it more obvious that it is code.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
RPG
Volunteer
Posts: 2257
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Opening a form with a button

Post by RPG »

Hello
RobynsEgg wrote:What am I missing?
Maybe you expect something more then opening the form but then you have wrong ideas about your code. I think start study this.

Romke
LibreOffice 24.2.4.2 on openSUSE Leap 15.6
UnklDonald418
Volunteer
Posts: 1558
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Opening a form with a button

Post by UnklDonald418 »

Based on your profile information you might consider upgrading to a later version of oO.

Here is something I use based on a post found here a while back. It might work for you.
Place the name of the form you want to open in Button->Properties->General->Additional Information of a Button linked to this macro. It will open/display the named form, and if you add a comma before a second form name the second form will be closed.

Code: Select all

REM  *****  BASIC  ****


'----- suite to open any form 
Sub OpenFormCloseForm_Button_Click1( oEv as variant )
'reads sOpenFormName & sCloseFormName separated by a comma from tag of calling button
Dim N1 as integer,N2 as integer, xpos as integer, ypos as integer
 Dim XX as string, sOpenFormName as string, sCloseFormName as string
 
'  Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
'  oMRI = CreateUnoService( "mytools.Mri" )  
   
XX=oEv.Source.Model.Tag ' get button's form from Additional information on button control
N1=len(XX)
N2=instr(XX,",")
If N2<>0 then
   sOpenFormName = left(XX,N2-1)
   sCloseFormName = right(XX,N1-N2)
else
   sOpenFormName = XX
   sCloseFormName = ""
endif


' this Basic routine shows different results for a Text, Spreadsheet and Presentation document
' Depending on the document type, a different set of interfaces are supported by the object
' A portion of the interfaces are common to all these document types representing
' the general functionality that documents of any type offer. In particular, all OpenOffice.org
' documents support the com.sun.star.document.OfficeDocument service, including the interfaces
' com.sun.star.frame.XStorable and com.sun.star.view.XPrintable. Another interface is
' com.sun.star.frame.XModel.
'      MsgBox ThisComponent.Dbg_SupportedInterfaces

If sOpenFormName<>"" then OpenForm( getFormsTC, getConnectionTC, sOpenFormName ) 

If sCloseFormName<>"" then ThisDatabaseDocument.FormDocuments.GetByName(sCloseFormName).close

End Sub

Function OpenForm( formContainer as variant, oConnection as variant, sFormName as string) as variant
Dim aProp(1) As New com.sun.star.beans.PropertyValue
aProp(0).Name = "ActiveConnection"
aProp(0).Value = oConnection
aProp(1).Name = "OpenMode"
aProp(1).Value = "open"
OpenForm = formContainer.loadComponentFromURL(sFormName,"_blank",0,aProp())
End Function
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
RobynsEgg
Posts: 6
Joined: Mon May 25, 2015 12:16 pm

Re: Opening a form with a button

Post by RobynsEgg »

@RoryOF - Will do in future. :)
@RPG - But it doesn't actually open the form? Will read the help file given
@UnklDonald - My apologies, I updated to 4.1.2 a while ago but failed to realize it does not automatically update my forum tag. :(
- I did read that in your earlier forum post but it didn't seem relevant in this case, which is why I did not include it? I JUST want to open the other form.
Robyn ~~~'~,~<@
OOffice 4.1.2 Win 8.1
UnklDonald418
Volunteer
Posts: 1558
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Opening a form with a button

Post by UnklDonald418 »

Either I don't understand what you mean by
want to open the other form
or you don't understand the macro presented above. It is designed to be reusable. Once installed there is no need to write a new macro every time you want to open a different form.
You create a button that points to this macro, and edit the button's properties with the name of the form you want to open. You can have one button on or whole menus of buttons calling this one macro.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
MTP
Volunteer
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: Opening a form with a button

Post by MTP »

Form2 in the attachment has three buttons. The first button calls the code I originally posted to open Form1, the second and third call the code posted by UnklDonald418 (the second just opens Form1, the third opens Form1 plus closes Form2).

All buttons work as expected on my system. Do they work on yours?
Attachments
OpenFormFromButton.odb
(19.21 KiB) Downloaded 1043 times
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
RobynsEgg
Posts: 6
Joined: Mon May 25, 2015 12:16 pm

Re: Opening a form with a button

Post by RobynsEgg »

@MTP - Incredibly, the answer is NO, those buttons also do nothing when I click on them...and that tells me what I was missing, and I corrected the security settings of my security programs and openoffice. My macro still didn't work, but I was able to learn from your example.

The first macro you used is the one I was asking for, just a simple oneliner to open the form. Sorry if I was confusing people.

Thank you so much!

UPDATE: It's my buttons that don't work! The buttons that were created on the sample demo that I was given work fine...it is just buttons I create that don't fire at all (even if I cut and paste the exact same code, word for word. (I should have gotten an error code "Form1 does not exist"... but nothing.

...though I realize that is another issue entire entirely so I will examine the forums before (if necessary) looking for guidance that way.
Robyn ~~~'~,~<@
OOffice 4.1.2 Win 8.1
User avatar
MTP
Volunteer
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: (SOLVED) Opening a form with a button

Post by MTP »

When you create a button, look at the properties window - on the tab "Events" are you pressing the "..." button next to "Execute" and then selecting your macro in the popup?
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
chris-nz
Posts: 6
Joined: Fri Jun 01, 2018 12:31 pm

[Solved] Re: Opening a form with a button

Post by chris-nz »

RobynsEgg wrote:@MTP - Incredibly, the answer is NO, those buttons also do nothing when I click on them...and that tells me what I was missing, and I corrected the security settings of my security programs and openoffice. My macro still didn't work, but I was able to learn from your example.

The first macro you used is the one I was asking for, just a simple oneliner to open the form. Sorry if I was confusing people.

Thank you so much!

UPDATE: It's my buttons that don't work! The buttons that were created on the sample demo that I was given work fine...it is just buttons I create that don't fire at all (even if I cut and paste the exact same code, word for word. (I should have gotten an error code "Form1 does not exist"... but nothing.
I had the same problem of the macro not executing when pressing the button, and once i set the Tools->Options->Open Office->Security->Macro Security then, i found that i needed to close down Open Office completely then reopen it before the macro would be executed by the button being pressed. :)
Apache OpenOffice 4.1.5 on Windows 10 Tablet
Yumi
Posts: 30
Joined: Fri Aug 29, 2008 3:54 am

Re: [Solved] Opening a form with a button

Post by Yumi »

Thanks for this a little older post, still solved my problem in 2024.
I only wondered why the macro always opened Form1 whatever I changed. Until I found in base - button control-properties - General when I scroll all the way down there is a field "Additional Information". This is where the name of the form to open and that of the form to close is entered.
Example: AA_Startpage,AM_Parameters (the comma is important for base to know which to close)
Hope the extra little info helps another beginner to macros and forms.
OOo 4.1.6 on Linux Mint 19.1 Tessa
Post Reply