Page 1 of 1
[Solved] Open a form without a macro
Posted: Sun Mar 27, 2016 7:04 pm
by maxi1991
Hi everybody, I want to know how i can open a form with a button without a macro.
Thanks in advance.
Re: Open a form without a macro
Posted: Sun Mar 27, 2016 7:24 pm
by Villeroy
Only if you save the form document as a stand-alone document.
A helper macro to extract and reconnect forms:
viewtopic.php?f=21&t=77543
Background:
viewtopic.php?f=83&t=40493
Re: Open a form without a macro
Posted: Sun Mar 27, 2016 8:13 pm
by maxi1991
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
Re: Open a form without a macro
Posted: Sun Mar 27, 2016 11:07 pm
by Villeroy
The tutorial describes it in detail.
The macro does it for you.
Re: Open a form without a macro
Posted: Wed Mar 30, 2016 1:22 pm
by Nocton
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
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
Re: Open a form without a macro
Posted: Wed Nov 29, 2017 11:08 pm
by johnh009
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
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
ThisDatabaseDocument.FormDocuments.GetByName(sCloseFormName).close
in the middle line of the following code:
Code: Select all
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
Re: Open a form without a macro
Posted: Thu Nov 30, 2017 1:39 am
by Villeroy
The error message is clear. A form named "ARASMenuForm" does not exist.
Re: Open a form without a macro
Posted: Thu Nov 30, 2017 2:31 pm
by johnh009
Seems to me that the form ARASMenuForm exists, unless I'm naming the form in the wrong place or something:
[img]
[/img]
Re: Open a form without a macro
Posted: Thu Nov 30, 2017 3:44 pm
by Nocton
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.
Re: Open a form without a macro
Posted: Thu Nov 30, 2017 5:22 pm
by Villeroy
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
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
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.
Re: Open a form without a macro
Posted: Thu Nov 30, 2017 6:14 pm
by johnh009
@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.