Ask Your Question
0

How to use a form button to open a report

asked 2018-01-22 18:23:20 +0200

mastertazo gravatar image

updated 2018-01-22 18:31:49 +0200

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)

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2018-01-22 19:49:56 +0200

Ratslinger gravatar image

updated 2018-01-23 15:05:29 +0200

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 ✔ (upper left area of answer). It helps others to know there was an accepted answer.

edit flag offensive delete link more

Comments

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 gravatar imagemastertazo ( 2018-01-23 11:17:26 +0200 )edit

@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.

Ratslinger gravatar imageRatslinger ( 2018-01-23 14:56:16 +0200 )edit
1

answered 2018-01-22 19:21:28 +0200

Spun69 gravatar image

updated 2018-01-22 19:35:36 +0200

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)
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-01-22 18:23:20 +0200

Seen: 984 times

Last updated: Jan 23 '18