Print Base Report via a Button

Is it possible to send a base report to a printer with a single button click? If so, how?

I have created a project tracking database with a number of reports. I can generate a report by assigning a macro to button on various forms, but these only open the report in writer. I still need to click the print button within writer.

Current macro that opens the report in writer:
Sub Open_rptProjectBasic
const sRptName=“rptProject Basic”
ThisDatabaseDocument.ReportDocuments.getByName(sRptName).open
End Sub

LO: 7.4.3.2
OS: macOS Big Sur 11.7.1

Thank you,
Doug

1 Like
Sub Open_rptProjectBasic
   oReport = ThisDatabaseDocument.ReportDocuments.getByName("rptProject Basic").open
   oReportView = oReport.CurrentController.Frame.ContainerWindow 'If you won't show the report, only print
   oReportView.Visible = False
   DIM Props
   DIM stPrinter AS STRING
   Props = oReport.getPrinter()
   stPrinter = Props(0).value
   DIM arg(1) AS NEW com.sun.star.beans.PropertyValue
   arg(0).name = "Name"
   arg(0).value = "<" & stPrinter & ">"
   arg(1).name = "Wait"
   arg(1).value = True
   oReport.print(arg())
   oReport.close(true)
End Sub

Opens the report, hides the reports, prints the report to default printer and closes the report.
If you have different reports you could set the name of reports to the tag of the buttton, which starts the report. So only one procedure is needed:

Sub OpenReport(oEvent AS OBJECT)
   stReport = oEvent.Source.Model.Tag
   oReport = ThisDatabaseDocument.ReportDocuments.getByName(stReport).open
…

@IslandLO : Corrected double quotes in Basic code now. Double quotes will only be correct when they will be shown as preformatted text.

Thank you Robert, that does it. Have a great new year.

If anyone is reading this in the future, there is a typo in the second line. The wrong double quotes are used in <“rptProject Basic”>. Just use the normal double quotes on your keyboard or cut/paste from others later in the macro.

I would mark this as solved, if I just knew how to do that.

You don’t mark the thread, but you can mark the post by @RobertG as solution. The site e(discourse) will then show the checkmark for the thread.