How to address a control in a report

Within a macro, how can I supply a value to a control in a report?

By way of example, I run a query to provide data for a report, then open the report:

orept = Thisdatabasedocument.reportdocuments.getbyname("R-ThisJob").open

I now wish to supply a title or header which is specific to that query, but is not contained in the answer table. The control is a label field with the name “Title”.

 oRept.PageHeader.Title.Label = "Something specific"

How do I address this? (What I have written obviously does not work - but conveys the intention.) With a form (called with the variable NextForm), I can use the following syntax:

main_form = NextForm.Component.getDrawPage().getForms().getByName("MainForm")
oField = main_form."FS_Name"
oField.label = Wanted

Is there a related syntax for addressing a control in a report? I haven’t been able to find relevant documentation.


This will present two methods to do what is wanted. Please understand these are Q&D reports and you should add safeguards and controls to insure correct processing. It is clean enough to present solutions with remarks in the code.

One method is to use a table similar to a Filter table. You can then input from a form & pass that on to the report through a query.

Another method is to actually modify the report. This needs to be done when the report is in edit mode. The report is accessed in sections and the fields are accessed through indexed items. You must check names for what you want. The edited report is saved as is the Base file. The report is executed with the change(s).

The titles for this second method are hard coded in the macro. You can easily have them entered through controls or an input box.

Sample ------- ModReportFromMacro.odb

Also, there are ways to modify the Writer file generated. You would access the appropriate sections. Have done this once a few years back for changing a field size. Not proficient with any of this so did not address here.

Many thanks for this: helpful as always. I prefer editing the report design. It is not really desirable to keep saving the modified report, so I tried executing it without saving. This worked perfectly well, generating a report with the desired heading without changing the saved version. BUT of course, by calling


without saving had the effect (as when one clicks on “Execute Report” from the design window) of successful execution, but when the executed report was closed, the report design window was still open and had to be closed manually. This is not really desirable from the point of view of the end-user, but I cannot see a way round it without saving and closing the design before executing the report.

The alternative, of creating ‘dummy’ fields in the table for the report, seems a ‘poor’ solution in terms of memory use (?), but for a table that is not enormous is perhaps the simplest one.


To eliminate requirement to save, only need to clear flag. Here is code which eliminates saving and closes edited window after report is generated:

Sub mod_Report
    Dim oParent As Object
    Dim oReport As Object
    Dim oReportDocuments As Object
    Dim oReportHeader As Object
    Dim oField As Object
    Dim oCurrentController As Object
    Dim oFrame As Object
    Dim x As Integer
Rem open report in design mode
    oParent = ThisComponent.getParent()
    oReportDocuments = oParent.getReportDocuments()
    oReport = oReportDocuments.getByName("JustSomeInfo").openDesign()
Rem may need "Wait 300" here if items don't change
Rem Get section wanted
Rem ReportHeader, ReportFooter, PageHeader, PageFooter, Detail
Rem Section may have DataFields here - field:[Publication code]
    oReportHeader = oReport.ReportHeader

Continued in next comment

cont —

Rem Loop through items - No forms hre - only access by index
    For x = 0 to oReportHeader.Count - 1
        oField = oReportHeader.getByIndex(x)
Rem Check if wanted field by using name
Rem Can use Input boxes here for entering your titles
        If oField.Name = "MainLF" Then
            oField.Label = "Another"
        End If
        If oField.Name = "SubLF" Then
            oField.Label = "Secondary"
        End If
    Next x
Rem Clear modified flag to not equire saving
Rem Need access to Report frame to Save & Close
    oCurrentController = oReport.getCurrentController()
    oFrame = oCurrentController.getFrame()
Rem Close edited report window
End Sub

If this answers your question please tick the :heavy_check_mark: (upper left area of answer).

Another piece of code you can add is to either change the edited report to not visible or minimized:

    Dim oContainerWindow As Object
    oFrame = oReport.getCurrentController().getFrame()
    oContainerWindow = oFrame.ContainerWindow
Rem    oContainerWindow.setVisible(False)
    oContainerWindow.IsMinimized = True

Place this code after the openDesign line & choose the visible or minimized line to execute.

Thank you again: this could have multiple uses.