Base: Print Button

I am trying to use this database as a basis to continue working with.

The intention is to create a button to print the current invoice.
From the Invoices form, I can create a button to open a report. I’m also able to enter the desired InvoiceID via a query.
But I’m not able to pass the correct InvoiceID to the query through the button (a macro?) So that everything runs automatically.

Does anyone have a solution? I have already visited hundreds of sites, but with no succes.



There are different methods to accomplish what you ask for. Attached is the sample you have provided. It has a filter table included (one record) to hold the invoice # to be printed. The query was modified to use this field for report selection. There is a separate form, PrintInvoice for selection of what is to be printed. It contains a list box to select the wanted invoice and a push button. The push button is attached to a short macro:

Option Explicit

Sub OpenReport
    Dim oController As Object
    Dim oReportDoc As Object
    oController = ThisDatabaseDocument.currentController
    if not oController.isconnected then oController.connect
    oReportDoc = Thisdatabasedocument.reportdocuments.getbyname("rpt_Invoice-pt2").open
End Sub

which executes the report.

Sample — odb78-Invoice-pt4c-TheInvoice.odb

There are other ways to do this such as creating a table containing just what is to be printed. See as reference → Asking for help with Temporary Tables y LibreOffice Base and also → How does the “SELECT INTO” work in Base. There are certainly other methods.

You could also include a field in the record for print selection and base printing upon this being set. You do need to clear the field after printing.

Edit 2020-05-19:

Have modified the first sample. Still uses the filter table. Just a matter of movint the ID to the table and then print the form. Button added to Invoices form. This button is attached to PrintCurrent macro.

Sample ------ odb78-Invoice-pt4c-TheInvoice.odb


Thanks for your reply. Your sample does the job. But with a lot of invoices not an easy way to work with.

However, I want to be able to click on a button on the invoice form to print without making another selection. InvoiceID should be the value I want to use in the query. No idea how.

An extra field ‘printing Yes/No’ works better but then I need to clear that field after printing which is no big deal of course.

Still looking for an automatic solution.


Have modified the sample. As stated there are many possibilities and when you look at the code you will see it is just moving the proper data from one place to another (one field). Since this was a sample from a tutorial it seemed you would be doing something different anyway.

Again many ways to accomplish and it is simply up to your needs.

@ Ratslinger
Wow, super!!! This is what I was looking for.
I’m going to study how you fixed this. Thanks a lot.

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.