Printing the report for the current form only (invoice)

Hello,
I forgot on previous posts to mention that I m total newbie and hope the questions are not annoying. After setting up invoices to be printed, the only way I found to get this working is to use a macro found on her (see below) now this will print all the forms that have been written, of course I would like to print only that one form I am working on. Is there a way to get this done ? and given I do not know about macros at all, is there a way to get to print from a form without using a macro?
Thanks much!

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

Hello,

Each time you ask a question please include the specific LO version, your OS and for Base the database used and connection information when present. You are probably using HSQLDB embedded or Firebird Embedded (both included with LO) but nothing is specified.

Specifying each time eliminates the need to search back through possible previous questions. This information can determine how the question is answered.

Hello,

Best to avoid macros whenever possible especially when new to Base/LO.

The easiest manner to print a selected item is using a parameter in your query. This begins with a colon and followed with text for a prompt. Example is :myEntry

This is then used in the Where section of the SQL:

Select “MyName”, “MyAddress”, “InvoiceNo” from “MyTable” Where “InvoiceNo” = :myEntry

When executed you will be prompted for a value and the query will select based upon that entry.

For more information see → Query Design

As with all questions, 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 so much for the advice and hints Ratslinger, helps a lot!

That worked like a cham, many thanks! is there a way the print(per query) could be called by a button within the form?

@Chris-H,

Yes there are ways to call this from a button on a form. Yes there are ways for the value to be obtained from the form when a button is pressed. Yes there are many ways to do so many things but a lot of this take some macro coding. Not something you learn in a week or two even with other programming experience.

There is a sample of using a button/macro to run a report in my answer here → How to disable LO Base report menu and Edit bar

Again, many thanks for your answers, time and understanding.