How to use a form button to open a report

Hi,

On Base,

I want to have a button on a form that opens a specific report.

I was able to make a query for the report based on the form, but not open the report itself

Idealy the button would save the current record and call the report, but if it is very dificult i can allwais set one button to save the record and another to open the report

Thanks in advance

I am using Libre Office Version: 5.4.3.2 (x64)

In my application, I use the Access2Base library. Then I use DoCmd.OpenReport(“name”) from within a macro which is invoked from button press.

Behind the scenes, the following code is executed:

Global Const acViewNormal = 0
Global Const acViewDesign = 1

lComponent = com.sun.star.sdb.application.DatabaseObject.REPORT

Set oController = oDatabase.Document.CurrentController
Set oObject = oController.loadComponent(lComponent, sObjectName, acViewNormal)

Hello,

You can only do this using a macro. You would attach the macro to the Execute action event of the button. The routine needs to be modified for the internal name of your form & the specific name of the report to be generated. Here is the macro:

Sub OpenReport
    oDrawPage = ThisComponent.getDrawPage()
    oForm = oDrawPage.Forms.getByName("YOUR_INTERNAL_FORM_NAME_HERE")
    If oForm.IsNew then
        oForm.insertRow()
    else
        oForm.updateRow()
    EndIf
    ocontroller = Thisdatabasedocument.currentController
    if not ocontroller.isconnected then ocontroller.connect
    oreportdoc = Thisdatabasedocument.reportdocuments.getbyname("REPORT_NAME_HERE").open
End Sub

This routine first updates or inserts the current record then executes the report.

If you are not familiar with macros you should refer to the LO documentation - found here.

Edit 1/23/2018:

To further help, attached is the sample I used for testing prior to posting the answer. This contains one table, query, form and report. The form contains the button which updates/inserts the table record and then executes the report.

Sample - ButtonToStartReport.odb

If this answers your question please tick the :heavy_check_mark: (upper left area of answer). It helps others to know there was an accepted answer.

Thank you for your anwer, but it did’t work.

I created the macro and changed the button content according to your instructions, but nothing happens when i click the button.

I even tryed to run the macro just to see if there was an error message but nothing happen

Could it be that macros are disabled ? where do I enable them?

Thanks in advance.

@mastertazo I have edited my answer to include the sample created. This should assist in helping you discover where your implementation went bad. Security is under menu item Tools->Options then under LibreOffice->Security. Select Macro Security... button then set to Medium.