[Solved] Open a form without a macro
[Solved] Open a form without a macro
Hi everybody, I want to know how i can open a form with a button without a macro.
Thanks in advance.
Thanks in advance.
Last edited by Hagar Delest on Sat Dec 02, 2017 6:04 pm, edited 1 time in total.
Reason: tagged [Solved].
Reason: tagged [Solved].
OpenOffice 4.1.1 on Windows 10
Re: Open a form without a macro
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
A helper macro to extract and reconnect forms: viewtopic.php?f=21&t=77543
Background: viewtopic.php?f=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 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Open a form without a macro
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
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
Re: Open a form without a macro
The tutorial describes it in detail.
The macro does it for you.
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 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Open a form without a macro
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
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
OpenOffice 4.1.12 on Windows 10
Re: Open a form without a macro
Having installed the above macro, when attempting to call a second form (Testform_01) from the first (ARASMenuForm) the following message is displayed:
The second - called - form is opened as is the macro (in edit mode) with text highlighted as follows:
in the middle line of the following code:
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
Code: Select all
BASIC runtime error.
An exception occurred
Type: com.sun.star.container.NoSuchElementException
Message: ARASMenuForm.
Code: Select all
ThisDatabaseDocument.FormDocuments.GetByName(sCloseFormName).close
Code: Select all
If sOpenFormName<>"" then OpenForm( getFormsTC, getConnectionTC, sOpenFormName )
If sCloseFormName<>"" then ThisDatabaseDocument.FormDocuments.GetByName(sCloseFormName).close
End Sub
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
Re: Open a form without a macro
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 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Open a form without a macro
Seems to me that the form ARASMenuForm exists, unless I'm naming the form in the wrong place or something:
[img] [/img]
[img] [/img]
LibreOffice 5.2.6.2 (Build ID:1:5.2.6-1). Linux (Sparkylinux based on Debian) 4.8
Re: Open a form without a macro
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.1.12 on Windows 10
Re: Open a form without a macro
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:
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:
If Sub OpenEmbedded can be found in the same lib as the calling routine you don't need to load any library.
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
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
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Open a form without a macro
@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.
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