Ask Your Question

How do I create a print form macro button [closed]

asked 2013-11-17 18:10:13 +0100

Libre Lyrae gravatar image

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??

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2015-11-17 01:45:26.054943

2 answers

Sort by » oldest newest most voted

answered 2013-11-17 20:12:26 +0100

MQ-818 gravatar image

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"


            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)

edit flag offensive delete link more


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

Libre Lyrae gravatar imageLibre Lyrae ( 2013-11-17 22:53:20 +0100 )edit

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.

MQ-818 gravatar imageMQ-818 ( 2013-11-18 01:25:06 +0100 )edit

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 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!

Libre Lyrae gravatar imageLibre Lyrae ( 2013-11-18 03:04:16 +0100 )edit

My Version: 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)

MQ-818 gravatar imageMQ-818 ( 2013-11-18 04:24:00 +0100 )edit

So, I tried 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.....

Libre Lyrae gravatar imageLibre Lyrae ( 2013-11-20 23:08:41 +0100 )edit

answered 2013-12-31 16:37:30 +0100

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

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2013-11-17 18:10:13 +0100

Seen: 2,714 times

Last updated: Dec 31 '13