Macros to open a report from a button

Discuss the database features
Post Reply
whosdaman
Posts: 12
Joined: Mon Feb 06, 2012 3:11 pm

Macros to open a report from a button

Post by whosdaman »

I need the code to open a report from a button. i used the code

Code: Select all

Sub OpenMyReport(oEvent As Object)

Dim RptName as string

RptName = "FeeCalculation"
ThisDatabaseDocument.ReportDocuments.getByName(RptName).open

End Sub
this gives an error i,e, the object variable is not set and it points to this code

Code: Select all

ThisDatabaseDocument.ReportDocuments.getByName(RptName).open
OpenOffice 3.3 Ubuntu 11.10
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Macros to open a report frm a button

Post by RPG »

Hello

I think the thread [Example] OpenForm with macros can give you also the information about opening a report.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
whosdaman
Posts: 12
Joined: Mon Feb 06, 2012 3:11 pm

Re: Macros to open a report frm a button

Post by whosdaman »

That has nothing about opening reports via a button...... so that didnt really help but thanks anyway
OpenOffice 3.3 Ubuntu 11.10
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macros to open a report frm a button

Post by RoryOF »

If it tells how to open a report using a macro, you then need to search for how to link a macro to a button.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macros to open a report from a button

Post by Villeroy »

RPG wrote:Hello

I think the thread [Example] OpenForm with macros can give you also the information about opening a report.

Romke
No, in that thread I redirected someone to use stand-alone form documents without any macros. Unfortunately, this does not apply to reports which is one reason why I prefer spreadsheet reports.

The first message of this topic contains macro code to open a report with the hard coded name "FeeCalculation" stored in the same database document as the macro.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
whosdaman
Posts: 12
Joined: Mon Feb 06, 2012 3:11 pm

Re: Macros to open a report from a button

Post by whosdaman »

could someone just please tell me why the error is coming and why the code is not working???

i know how to assign a macro to a button and i would like to know why the macros i posted is not working as it should
OpenOffice 3.3 Ubuntu 11.10
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Macros to open a report from a button

Post by RoryOF »

Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
DACM
Volunteer
Posts: 1138
Joined: Tue Nov 03, 2009 7:24 am

Re: Macros to open a report from a button

Post by DACM »

That code seems to work as long as you have a report name "FeeCalculation" (case sensitive). And the code is saved to your .odb file (i.e. not MyMacros).

Code: Select all

Sub OpenMyReport '(oEvent As Object)
    RptName = "FeeCalculation"
    ThisDatabaseDocument.ReportDocuments.getByName(RptName).open
End Sub
AOO 4.1.x; LO 4.2.x; Windows 7/8 64-bit
Warning: Avoid embedded databases --> Solution: Adopt a portable 'split database' folder
Soli Deo gloria
whosdaman
Posts: 12
Joined: Mon Feb 06, 2012 3:11 pm

Re: Macros to open a report from a button

Post by whosdaman »

Thank you DAMC that worked i saved the macros into MyMacros and when i shifted it into .odb file and it worked.

i wanted to ask one last thing that i have made a report that requires you to enter the student id is it possible to edit the macros such that it will take the student id value from the form text box
OpenOffice 3.3 Ubuntu 11.10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macros to open a report from a button

Post by Villeroy »

Yes, it is possible indeed.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
whosdaman
Posts: 12
Joined: Mon Feb 06, 2012 3:11 pm

Re: Macros to open a report from a button

Post by whosdaman »

could someone please tell me how to do this??

any sample code or anything......

Thanks in advance
OpenOffice 3.3 Ubuntu 11.10
RPG
Volunteer
Posts: 2250
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Macros to open a report from a button

Post by RPG »

Hello

You clearly did not study the second example but I have the idea that it is not good for you to work with macros. I think follow the way of Villeroy and try to do it without macros.

Romke
LibreOffice 7.1.4.2 on openSUSE Leap 15.2
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macros to open a report from a button

Post by Villeroy »

As far as I know, it takes a macro to open embedded objects by push button. We get rid of this limitation when we open stand-alone documents by means of ordinary hyperlinks. Any office document can have forms attached.
There are no reports outside the Base document except for Calc sheets with linked import ranges. WIth a little bit of hand made column layout, page styles and cell styles Calc can be fine tuned to serve as additional report generator not as good looking as Writer documents but with a lot of extra functionality.

Loading reports and forms filtered by current form content is possible without macros if the filter criteria are stored in some filtering record. Search this forum for "power filtering" by user Arineckaig.

Filtering record sets by macros requires programming skills even when you copied the methods from existing code. The details depend on the exact data types and how to substitute parameters with programatic variables of appropriate types.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
cazbym
Posts: 40
Joined: Wed Apr 15, 2009 2:52 pm

Re: Macros to open a report from a button

Post by cazbym »

I have managed to open reports using the DBDocShortCuts extension and using this to create a shortcut to a report and then assigning the shortcut .bat file to the execute event of a push button. It seems to work.
Windows 10
OOo 4.1.5
connected to
External HSQLDB 2.3.2 DB
Post Reply