How do I create a print form macro button

I am trying to create macros in LibreOffice Base but of course the macro recorder is limited in base and will not switch forms and such. I don’t have the time to learn Basic programming – I’m more interested in learning Python if I had to choose. All I need is the code to go from a form to a report and print it. Even if I could just get the code to open a form. I had tried the following from an example I saw on You-tube but got an error saying “Basic Runtime Error: Object Variable Not Set”

Sub OpenForm_1
const sNewDocumentName=“Cheque Writing Form”
oNewFormDocument=ThisDataBaseDocument.FormDocuments.getbyname(sNewDocumentName).open
end sub

Can someone help me fix the above macro, OR is there a collection of already written macros somewhere that I can use/modify??

USE the below macro to preview the report first…Once preview you can print from top menu choosing PRINT.

           Sub Open2PreviewReport_100(oEvent As Object)

                      Dim RptName as string

                      'the name of the report I want to open

                      RptName = "rpt_100_CustAppt"

                 ThisDatabaseDocument.ReportDocuments.getByName(RptName).open

            End Sub

Steps to follow>>>>

  1. In your form Create a Button

  2. On click of the Button put this as a Macro (Of course edit my macro to fit your document name)

Thanks for the quick response, however when I used: :

Sub OpenChequeReport(oEvent As Object)
Dim RptName as string
'the name of the report I want to open
RptName = “Cheque Printer”
ThisDatabaseDocument.ReportDocuments.getByName(RptName).open
End Sub

I still got the same BASIC runtime error. Object variable not set. And it pointed at:
ThisDataBaseDocument.ReportDocuments.getByName(RptName).open

Will you please change your Report name? Change FROM “Cheque Printer” TO “Cheque_Printer” OR “ChequePrinter” and try again. Some how I think the space in the report name isn’t allowed!!! Might be wrong. I know the code that I send you is working code, because I just copy paste from my working form/macro.

I changed the name of the report and it still gave the same error - but will remember the spaces in the name for next time, thanks. As a test I ran it on my laptop running LO 4.1.1 (LO 4.0.0.3 on office desktop) and I got the same error - I know my Base Reports either work well or don’t at all in different versions of LO Base - could this be an issue like that? I REALLY appreciate your help and suggestions!

My Version: 4.1.2.3
Build ID: 40b2d7fde7e8d2d7bc5a449dc65df4d08a7dd38

If you can update your to this version and try it. Also I am using HSQL database engine (see it at the bottom) with Macro Enabled (asks when open the BaseDB)

So, I tried 4.1.2.3 and it still did not work (On Ubuntu 13.4), and neither did my reports I mentioned. I also tested the newest 4.1.3 and the macro still did not work, but interestingly my reports seemed to work beautifully. Go figure. Anyway still trying to get open form macros to work…

I had the same error. The examples worked fine, but when I copied the code to mi own macro I got this error. After defining the statement:
Option explicit ’ make sure you have to define all variables
this error was solved.
Define it as one of the first lines in your macro.

Hope this will help