How do I add template name to status bar of libreoffice writer? - libreoffice

Here is a line from the file statusbar.xml from \share\config\soffice.cfg\modules\swriter\statusbar
<statusbar:statusbaritem xlink:href=".uno:PageStyleName" statusbar:align="left" statusbar:autosize="true" statusbar:width="79"/>
I copied the file to user directory: \config\soffice.cfg\modules\swriter\statusbar
I just need to display Template Name from document properties. for e.g.
ThisComponent.getDocumentProperties().TemplateName
But adding this line does not work as expected. It creates a width of 79 pixels but does not show template name.
<statusbar:statusbaritem xlink:href=".uno:ThisComponent.getDocumentProperties().TemplateName" statusbar:align="left" statusbar:autosize="true" statusbar:width="79"/>
The purpose is to show current document's template name in status bar just like style name.
Update:
I got this code from "Useful Macro Information For OpenOffice.org By Andrew Pitonyak".
It is working as expected. But it does not show any other items on status bar. I need TemplateName next to style name.
Function ProgressBar
ProgressBar = ThisComponent.CurrentController.StatusIndicator
End Function
Sub StatusText()
Dim sInformation
Dim iLen as Integer
Dim iRest As Integer
sInformation = ThisComponent.getDocumentProperties().TemplateName
iLen=Len(sInformation)
iRest=350-iLen
ProgressBar.start(sInformation+SPACE(iRest),0)
End Sub

Those are UNO dispatcher commands, not Basic code. It looks like there are only a few that would work, such as .uno:CharFontName or .uno:FrameName. Most UNO commands perform an action rather than getting information.
At https://forum.openoffice.org/en/forum/viewtopic.php?t=10104, there is Basic macro code to set the status indicator:
ThisComponent.CurrentController.StatusIndicator.Start(vStatusBarText,0)
If it's possible to call a macro from statusbar.xml, then the syntax would be like this:
xlink:href="vnd.sun.star.script:pythonSamples|TableSample.py$createTable?language=Python&location=share" \
xlink:type="simple"
EDIT:
Here is a Basic call example, from https://ask.libreoffice.org/t/how-to-translate-the-toolbar-into-multiple-languages/42404:
xlink:href="vnd.sun.star.script:Standard.Module6.gerer_cadre_image1?language=Basic&location=application"

Related

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.

libreoffice base macro parametric open close get current form name

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

Using RecordSource to change form contents

I am trying to create a method that displays a selected table in a DS view form. The form will be used repeatedly to view different tables, so I figured the easiest way would be to create a form and dynamically change the RecordSource based on the user selection.
I created a form called "frmDisplay" to be used to display the contents of a table to the users. I am trying to use this code to update the form.
Private Sub btnViewEntries_Click()
Dim frmDisplay As Form
Dim selection As String
Me.cmboSelection.SetFocus
selection = "tbl" & Me.cmboSelection.Text
Set frmDisplay.RecordSource = selection
DoCmd.OpenForm "frmDisplay", acFormDS
End Sub
Currently, the code is throwing an "Improper use of property" error when I try to set the RecordSource to the selection made in the combo box.
Set frmDisplay.RecordSource = selection
I have looked around for a while now, but I cannot seem to find any definitive answer that applies to this example. Most posts that I found were missing the Set keyword...
Does anyone recognize the problem? More importantly, is this even the best way to make this
work?
Thanks
_____ EDIT _____
I figured it out, see code below.
Dim selection As String
Me.cmboSelection.SetFocus
selection = "SELECT * from tbl" & Me.cmboSelection.Text
DoCmd.OpenForm "frmDisplay", acDesign
Forms!frmDisplay.Form.RecordSource = selection
DoCmd.Close acForm, "frmDisplay", acSaveYes
DoCmd.OpenForm "frmDisplay", acFormDS
I note you've already provided your answer, but you may find the following helpful.
If you have a main form with the controls cmboSelection and btnViewEntries then add a subform control and call it fsbDisplay. Don't put anything in this subform, leave it unbound.
Now try the following one-liner:
Private Sub btnViewEntries_Click()
fsbDisplay.SourceObject = "Table.tbl" & cmboSelection.Value
End Sub
The advantage of this method is that you can use it to call up any table or query (prefix with Query. instead of Table.) and the fields shown are dynamically created.

MS Access VBA Function Result in Form Text Box Control

I've written a custom VBA function and would like the output to print out into a text box. The function is simple but I keep getting #Name in the text box.
What is the proper way to set the Control Source to a custom VBA function in an Access Form Text Box?
This is a vague question ...
Control Source : =MyFunction()
You should, of course, check that the function works. The immediate window is useful for such testing. You can also use an event to get the result and set the value of the textbox.

How is non-standard worksheet.object created in this Excel VBA

The following VBA 6 in Excel 2000 code
Resides in a form that has text boxes, comboboxes and buttons
One of them is txtUsername, another is txtPassword
--I inherited this code
With shtName
.Unprotect "thepassword"
.range("somenamedrange").Value = cboComboBox.Value
.txtUsername.Text = txtUsername.Text
.txtPassword.Text = txtPassword.Text
...
End With
The code sets a text value for two worksheet objects that appear in the VBA Editor Object list, but are neither defined nor set anywhere else in the Excel Project. Option Explicit is used on all Microsoft Excel Objects, Forms and Modules. I can create procedures for said worksheet objects on said worksheet in the VBA Editor (e.g.,
Private Sub txtUsername_Change()
End Sub
Neither object
worksheet.txtUsername
worksheet.txtPassword
appears nor is set as a named range.
The value of both objects is only used elsewhere by specific reference worksheet.txtUsername.Text
These values do not show up in the locals window after they are set on the worksheet. They are definitely used, as the Essbase queries complete successfully using these objects.
summary:
i understand formName.txtUsername.Text (or .Value)
i do not understand a worksheet object that does not get defined nor instantiated via code
the only bright idea I had was to export the worksheet and view in a text editor, to see if my ancestors created a "custom" worksheet object the way one defines a "default property" in a class module--manually via text editor
(no mention of either property in the worksheet.cls)
Thank you.
Worksheets that are part of the Excel spreadsheet do not have to instantiated, they're part of the workbook and just "always there". If they're not visible to the user but are visible in the project browser, there could be some code in the "ThisWorkbook" section that make the sheets invisible (.visible = false) when the workbook launches.
I found that the VBA Code Cleaner cleaned "references to object definitions that cannot be found".