[Solved] Open a form without a macro

Creating and using forms

[Solved] Open a form without a macro

Postby maxi1991 » Sun Mar 27, 2016 7:04 pm

Hi everybody, I want to know how i can open a form with a button without a macro.


Thanks in advance.
Last edited by Hagar Delest on Sat Dec 02, 2017 6:04 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 4.1.1 on Windows 10
maxi1991
 
Posts: 7
Joined: Sun Mar 27, 2016 6:35 pm

Re: Open a form without a macro

Postby Villeroy » Sun Mar 27, 2016 7:24 pm

Only if you save the form document as a stand-alone document.
A helper macro to extract and reconnect forms: https://forum.openoffice.org/en/forum/v ... 21&t=77543
Background: https://forum.openoffice.org/en/forum/v ... 83&t=40493
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26626
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open a form without a macro

Postby maxi1991 » Sun Mar 27, 2016 8:13 pm

ok after of save as stand alone document. How can i reconect the form like a form and not like a document.
I know that in button properties select in action open document/web page and select the form document but i want to know how i can open like a form to work like a form and no like a document
OpenOffice 4.1.1 on Windows 10
maxi1991
 
Posts: 7
Joined: Sun Mar 27, 2016 6:35 pm

Re: Open a form without a macro

Postby Villeroy » Sun Mar 27, 2016 11:07 pm

The tutorial describes it in detail.
The macro does it for you.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26626
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open a form without a macro

Postby Nocton » Wed Mar 30, 2016 1:22 pm

Open the Properties of your Control Button.
1. In 'Additional Information' put the name of the form you wish to open and then the name of the form you wish to return to after you close the first form thus: FormtoOpen,FormtoReturnto
2. Put the code below into your Basic macro area
3. Set the 'Mouse button released' event to the macro OpenFormCloseForm_Button_Click .

Regards

Nocton

Code: Select all   Expand viewCollapse view
Sub OpenFormCloseForm_Button_Click( oev as variant )
'reads sOpenFormName & sCloseFormName separated by a comma from tag of calling button
Dim XX, sOpenFormName, sCloseFormName as string
Dim N1,N2 as integer
XX=oev.Source.Model.Tag
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
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

function getFormsTC() as variant
getFormsTC = thisComponent.Parent.getFormDocuments
End function

function getConnectionTC() as variant
getConnectionTC = thisComponent.Drawpage.Forms(0).ActiveConnection
End function
OpenOffice 4.2.0 on Windows 10
Nocton
Volunteer
 
Posts: 497
Joined: Fri Nov 05, 2010 10:27 am
Location: UK

Re: Open a form without a macro

Postby johnh009 » Wed Nov 29, 2017 11:08 pm

Having installed the above macro, when attempting to call a second form (Testform_01) from the first (ARASMenuForm) the following message is displayed:

Code: Select all   Expand viewCollapse view
BASIC runtime error.
An exception occurred
Type: com.sun.star.container.NoSuchElementException
Message: ARASMenuForm.


The second - called - form is opened as is the macro (in edit mode) with text highlighted as follows:

Code: Select all   Expand viewCollapse view
ThisDatabaseDocument.FormDocuments.GetByName(sCloseFormName).close


in the middle line of the following code:

Code: Select all   Expand viewCollapse view
If sOpenFormName<>"" then OpenForm( getFormsTC, getConnectionTC, sOpenFormName )
If sCloseFormName<>"" then ThisDatabaseDocument.FormDocuments.GetByName(sCloseFormName).close
End Sub


The same error is produced in both 'mouse realeased' or 'execute action'.

System info:

LibreOffice 5.4.2.2.0. Split database using HSQLDB 2.4.0. Sparkylinux 4.13.0-1-amd64
LibreOffice 5.2.6.2 (Build ID:1:5.2.6-1). Linux (Sparkylinux based on Debian) 4.8
johnh009
 
Posts: 7
Joined: Thu Mar 16, 2017 2:00 pm

Re: Open a form without a macro

Postby Villeroy » Thu Nov 30, 2017 1:39 am

The error message is clear. A form named "ARASMenuForm" does not exist.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26626
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open a form without a macro

Postby johnh009 » Thu Nov 30, 2017 2:31 pm

Seems to me that the form ARASMenuForm exists, unless I'm naming the form in the wrong place or something:

[img]
Screenshot%20at%202017-11-30%2012-24-08.png
[/img]
Attachments
Screenshot at 2017-11-30 12-24-08.png
LibreOffice 5.2.6.2 (Build ID:1:5.2.6-1). Linux (Sparkylinux based on Debian) 4.8
johnh009
 
Posts: 7
Joined: Thu Mar 16, 2017 2:00 pm

Re: Open a form without a macro

Postby Nocton » Thu Nov 30, 2017 3:44 pm

The problem may be that with one form called from another you may not have got the correct form names in to sCloseFormName and sOpenFormName. I suggest you set the watch window to follow the content of these two variables using breakpoints to stop at various points in the macro execution. Also check the tag contents/Additional information of each Control Button.
OpenOffice 4.2.0 on Windows 10
Nocton
Volunteer
 
Posts: 497
Joined: Fri Nov 05, 2010 10:27 am
Location: UK

Re: Open a form without a macro

Postby Villeroy » Thu Nov 30, 2017 5:22 pm

The macro should open the form document "ARAS Help Form" which contains the logical form "ARASMenuForm".
The form document is an embedded Writer document. The logical form provides the record set to its form controls and is loaded with the document.

This macro should open any embedded form or report:
Code: Select all   Expand viewCollapse view
Sub OpenEmbedded(odb, sHierachicalName$, bReport As Boolean)
   view = odb.CurrentController
   con = view.ActiveConnection
   if isNull(con) then view.connect()
   if bReport then
      container = odb.ReportDocuments
   else   
      container = odb.FormDocuments
   endif
   obj = container.getByHierarchicalName(sHierachicalName)
   obj.open()
End Sub

First argument odb is a database document. ThisDatabaseDocument refers to the database document which embeds the macro. ThisComponent (active document) should be used when the calling macro is not embedded in a database.
Second argument sHierarchicalName is a form or report name or a path-name when the object is in a folder ("folder_name/subfolder_name/form_name"). Embedded forms and reports can be organized in folders.
Third argument bReport is a boolean. True if the name refers to a report, false if the name refers to a form.

Having the above generic macro in a public library [My Macros].DBA, you can call it from an embedded macro like this:

Code: Select all   Expand viewCollapse view
GlobalScope.BasicLibraries.loadLibrary("DBA")
OpenEmbedded ThisDatabaseDocument, "ARAS Help Form", False

If Sub OpenEmbedded can be found in the same lib as the calling routine you don't need to load any library.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26626
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open a form without a macro

Postby johnh009 » Thu Nov 30, 2017 6:14 pm

@Nocton. Thank you for your prompt reply.

I wouldn't have been able to carry out your suggestions without more research or asking you, not being a programmer and certainly not familiar with OO/LO macro code! I did get it to work going from form Testform_01 back to ARASMenuForm, so ARASMenuForm obviously exists. After a bit more phaphing around and renaming ARASMenuForm, which didn't work, I renamed it back (to it's original name), retyped into the relevant data fields and it now works in both directions. I don't think it was a spelling error as I had checked it a million times - well maybe not quite - but cognitive dissonance may have played a hand!

Thanks again for your help, and the code in the first place.

Thanks also to Villeroy for your help. I will bookmark this page for future reference as it's all good useful stuff.

Update (2017/12/01 16:14): I discovered what I was doing wrong. When I created the forms, I gave them a name that briefly described it's purpose. The name of the form, in 'design' mode remains as 'Form' or 'MainForm' and I only changed the design name when I wanted to create a 'Menu' form and call the other form from it, thinking that that was the relevant place to change the name; Doh! It appears that both names must correspond.
LibreOffice 5.2.6.2 (Build ID:1:5.2.6-1). Linux (Sparkylinux based on Debian) 4.8
johnh009
 
Posts: 7
Joined: Thu Mar 16, 2017 2:00 pm


Return to Forms

Who is online

Users browsing this forum: No registered users and 1 guest