English
Ask Your Question
0

How do I create a print form macro button

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

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 close delete

2 answers

Sort by » oldest newest most voted
0

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

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 publish link more
0

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

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"

                 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)

edit flag offensive delete publish link more

Comments

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 ( 2013-11-17 22:53:20 +0200 )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 ( 2013-11-18 01:25:06 +0200 )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 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!

Libre Lyrae ( 2013-11-18 03:04:16 +0200 )edit

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)

MQ-818 ( 2013-11-18 04:24:00 +0200 )edit

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

Libre Lyrae ( 2013-11-20 23:08:41 +0200 )edit
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

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

Seen: 520 times

Last updated: Dec 31 '13