libreoffice base macro parametric open close get current form name - macros

libreoffice Base 4.3.3.2
Opening a Form page by name and then close the current page form like this work:
oForm = ThisDatabaseDocument.FormDocuments.getByName("SecondForm")
oForm.Open
oFormC = ThisDatabaseDocument.FormDocuments.getByName("CurrentForm")
oFormC.Close
but is there a way to close oFormC without writing by hand his name?
trying with:
oFormC = Event.Source.Model.Parent
oFormC = ThisDatabaseDocument.FormDocuments.getByName(Event.Source.Model.Parent)
oFormC = getParent()
return an error of var not set
Can't find any help in documentation.

The term 'form' in LibreOffice/OpenOffice is confusing because it refers both to the entire document (typically a Writer file) and also to each group of form controls inside that document. So each form document can have many forms (meaning a group of controls) inside it, and forms (groups of controls) can have sub-forms.
This code gets a form document (a Writer file embedded inside a Base file):
oDoc = ThisDatabaseDocument.FormDocuments.getByName("SecondForm")
This code gets the form that is a group of controls and that contains the control which triggered the macro: oForm = Event.Source.Model.Parent
Another way to get a group of controls inside the form document in which the macro was triggered: oForm = ThisComponent.drawpage.forms.MainForm
Replace "MainForm" with your actual form name - form here meaning a group of controls. You can see the names of forms and subforms that are inside a form document by opening the Form Navigator window. Make sure the toolbar Form Design is visible; the Form Navigator icon is the sixth from the left or top, looks like a rectangle with a compass in the upper right corner.
You may have guessed from the previous code how to close the document that is active when the macro is triggered:
ThisComponent.close

Related

Mapping parameters from embedded form within a form MSACESS

I am trying to get a query to update based on a value passed from a combo box within the same form. After I moved the form into a tabbed control box within another form it seems to have broken. I've tried mapping from the outer form to the combo box and still an error to provide parameters into the query.
The Outermost form is "workbench"
The tab control is "tabbed_space"
The inner form is "software_list"
The combo box is "cmb_server_selection
I have in the query
=[Forms]![workbench]![tabbed_space]![software_list]![cmb_server_selection]
What am I doing wrong?
Tab controls do not affect the "navigation path" of objects, the objects are still directly on their form.
To get objects on a subform, you need SubformControl.Form!Object
So it should be
=[Forms]![workbench]![software_list].Form![cmb_server_selection]
Note: this is easier to debug in the Immediate Window (Ctrl+g) than in the query (the form must be open of course) :
? Forms!workbench!software_list.Form!cmb_server_selection

Open Subform in Access in New Window

I have a form in access ("F_Filter") where I indicate parameters to filter a datable. Form F_Filter also contains a subform which shows the filtered datatable results on the same screen. This subform with the filtered results is named "Child400." Its Source Object is "F_FilterResults".
I would like to be able to 1) open the subform in a new window so all I see are the filtered results and 2) export the results to Excel.
Normally I would be able to open a form in a new window by creating a button and creating an on click event with the following code
DoCmd.OpenForm "NameOfForm", acFormDS
However, this code does not work when I put in "Child400" as the NameOfForm. I think this is because Child400 is a subform and is not recognized by Access.
I also tried DoCmd.OpenForm "[F_Filter]![Child400]", acFormDS to no avail. Note that I have also tried DoCmd.OpenForm "F_FilterResults", acFormDS which works fine but this table only contains the prefiltered results.
DoCmd.OpenForm "F_FilterResults"
is the correct form to open. "Child400" is (I assume) the name of the subform control. That is not a form that you can open.
Then you need to apply the same filter as you did to the subform instance. The same method you use now for the subform can be used for the separate form.
If you have trouble with that, please add the existing filter code to your question.
Edit
There is no magic behind what records a form shows. It is controlled by a couple of properties. The easiest way is probably to simply take them over to the new form.
Something like:
Sub OpenResults()
Dim fSub As Form, fNew As Form
Set fSub = Me!Child400.Form
DoCmd.OpenForm "F_FilterResults", acFormDS
Set fNew = Forms!F_FilterResults
fNew.RecordSource = fSub.RecordSource ' if you change the RecordSource in your code
fNew.Filter = fSub.Filter
fNew.FilterOn = fSub.FilterOn
fNew.OrderBy = fSub.OrderBy
fNew.OrderByOn = fSub.OrderByOn
End Sub

LibreOffice Basic get Elements from form

I'm trying to get value from textfield on the form.
sub Test(oEv)
oForm = oEv.Source.Model.Parent
textBox = oForm.getByName("Description")
MsgBox textBox.Text
end sub
There is an Exception: "Type: com.sun.star.container.NoSuchElementException" on the line "textBox = oForm.getByName". I have a text field with the name "Description" on the same form, where is the button I press to run this macro. What is wrong here?
Check that the name is the same case, not description.
Also, use the Form Navigator to determine whether the control is under the form in the hierarchy.
Have you tried using an introspection tool such as MRI or XrayTool to view the properties of oForm? With the tool, expand the form to see if it contains the Description control.
Often in Base, it is better to deal with the form as a recordset rather than reading the controls. Here is some sample code:
Sub ButtonClickHandler(oEvent as Object)
'com.sun.star.comp.forms.ODatabaseForm
oForm = oEvent.Source.Model.Parent
lDescriptionCol = oForm.findColumn("DESCRIPTION") ' from underlying query or table
Print(oForm.getString(lDescriptionCol))
BasicLibraries.LoadLibrary("XrayTool")
xray(oForm)
End Sub
For more ideas, see https://forum.openoffice.org/en/forum/viewtopic.php?f=39&t=38725.

MS Access: Enter a specific text in a form using command button from another form

I would like to ask for your help on the following issue in MS Access.
I had created a form "CustomerListF", filled with command buttons for each client. For each button, I had created the following code:
Private Sub cmd_outlets_ABC_Click()
DoCmd.OpenForm "OrderFormF"
Forms!OrderFormF!Outlets = "ABC"
End Sub
The button would then open another form "OrderFormF" and enter "ABC" in the textbox named "Outlets". However, I realized the second line of code (Forms!OrderFormF!Outlets = "ABC") would always create a phantom record in my subform, which is located in "OrderFormF", and this record would travel to other clients' forms. This phantom record is usually created when the commandbutton is clicked twice (double clicks or subsequent clicks). It is a headache when the record starts to shift around.
enter image description here
I would like to seek your advice for vba code to edit the second line of code.
Thank you.
This approach for filling the field in opened form is not good. OrderFormF initialization and second line of your code with assigning value to the field may be executed in different sequence, they are not synchronized.
In order to avoid this, you should pass the argument to OrderFormF by another way. I would recommend to use OpenArgs parameter:
DoCmd.OpenForm "OrderFormF",,,,,,"ABC"
And then in Load event of OrderFormF assign the value to textbox:
Me.Outlets = Me.OpenArgs
In this case the "ABC" value will be assigned to first row in the form or to new record, if form is empty. Before assigning you can select the row if you need to assign value not to the first row. Also this way will protect you against double click on button, Load event executed only once during first form opening

Access VBA Run Time Error 2465: Application-defined or object-defined error

I have a form named UI(Navigation Form) in MS Access 2010. I have two more subforms SEARCH and RESULTS as tabbed forms in UI. After I search in SEARCH form, when I click the RESULTS tab I want the value from a combo box named 'cmbID' in SEARCH to be displayed in a label named 'lblAIPIDDisp' in RESULTS form and then display additional labels. So, I gave the following code in the navigation Button Click Event:
Private Sub NavigationButton32_Click()
Form_RESULTS.lblAIPIDDisp.Caption = [Forms]![UI]![SEARCH].cmbID.Value
End Sub
But I get Run Time Error 2465. So, I tried searching in SEARCH form separately and gave the following code in Form Load Event of RESULTS form:
Private Sub Form_Load()
Form_RESULTS.lblAIPIDDisp.Caption = [Forms]![SEARCH].cmbID.Value
End Sub
Now, I searched in SEARCH Form and clicked on RESULTS form. I was able to see the value in Combo Box 'cmbID' in SEARCH Form in the label 'lblAIPIDDisp' in RESULTS Form. So, I think there is something wrong in referencing subforms RESULTS and SEARCH in the Navigation Form UI. Help needed in this point.