[Solved] Open Base Report from Writer

Discuss the database features
Post Reply
fuzzyluzzi
Posts: 22
Joined: Wed Feb 26, 2014 12:37 pm

[Solved] Open Base Report from Writer

Post by fuzzyluzzi »

I've seen this code for opening a report. It works well if run directly from the database. How would I change it to use an active connection with a registered Database from a Writer document.

Thanks

Code: Select all

Sub OpenMyReport(oEvent As Object)
Dim RptName as string
RptName = "Date Query"
'the name of the report I want to open
ThisDatabaseDocument.ReportDocuments.getByName(RptName).open
End Sub
Last edited by fuzzyluzzi on Mon Mar 30, 2015 7:15 am, edited 1 time in total.
OpenOffice 4.0.1 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open Base Report from Writer

Post by Villeroy »

The following code has mostly been recorded using the MRI object inspection tool.
[Tutorial] Introduction into object inspection with MRI
The code can open any report from any form control that is attached to any form connected to any data source. Just add the name of your report to the form control's "Additional Info". In your particular case you set "Date Query" (without quotes) as "Additional Info" of your push button.

Code: Select all

Sub OpenReportByTag(oInitialTarget As Object)
  Dim oSource As Variant
  Dim oModel As Variant
  Dim oParent As Variant
  Dim oActiveConnection As Variant
  Dim oParent2 As Variant
  Dim oDatabaseDocument As Variant
  Dim oReportDocuments As Variant
Dim sRepName, oReport
  oSource = oInitialTarget.Source
  oModel = oSource.getModel()
sRepName = oModel.Tag
  oParent = oModel.getParent()

  oActiveConnection = oParent.ActiveConnection
  oParent2 = oActiveConnection.getParent()
  oDatabaseDocument = oParent2.DatabaseDocument
  
  oReportDocuments = oDatabaseDocument.getReportDocuments()

oReport = oReportDocuments.getByName(sRepName)
oReport.open()
End Sub
So far this code finds the correct database document and the correct report document therein. It does even open the requested report but it won't be filled with data unless I have visible instance of that database with its own active connection (one click on the tables section connects the database). The form's connection is not able to fill the report. This is beyond me. I don't have the time to get behind this. I'm happy with my Calc reports that work out of the box. These things used to work so much better in OpenOffice 1.x when there were no Base documents and all forms and reports were stand-alone Writer documents.
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
fuzzyluzzi
Posts: 22
Joined: Wed Feb 26, 2014 12:37 pm

Re: Open Base Report from Writer

Post by fuzzyluzzi »

so because there is no active connection, which is the error I get, I cannot run this report from anywhere but the actual database file. lame.
OpenOffice 4.0.1 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open Base Report from Writer

Post by Villeroy »

I'm 90% sure it can be done but I don't have the time nor patience to find out how.
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
F3K Total
Volunteer
Posts: 1038
Joined: Fri Dec 16, 2011 8:20 pm

Re: Open Base Report from Writer

Post by F3K Total »

Villeroy wrote:I'm 90% sure ...
now you can be 100% sure ...

Code: Select all

Sub OpenReportByTag(Event As Object)
    Dim oParms(0) As New com.sun.star.beans.PropertyValue
    oButton = Event.Source.Model
    sRepName = oButton.tag
    oParent = oButton.Parent
    oActiveConnection = oParent.ActiveConnection
    oDatabaseDocument = oActiveConnection.Parent.DatabaseDocument
    oReportDocuments = oDatabaseDocument.ReportDocuments
    oParms(0).name = "ActiveConnection"
    oParms(0).value = oActiveConnection
    ocomponent = oReportDocuments.loadComponentFromURL(sRepName, "", 0, oParms())
End Sub
R
  • MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
  • my current system
  • Windows 10 AOO, LOLinux Mint AOO, LO
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open Base Report from Writer

Post by Villeroy »

Thank you. How could I find out that "ActiveConnection" can be used as a property argument to loadComponentFromURL?
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
F3K Total
Volunteer
Posts: 1038
Joined: Fri Dec 16, 2011 8:20 pm

Re: Open Base Report from Writer

Post by F3K Total »

here? (details)
... but i just copied the code from somewhere else ...
R
  • MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
  • my current system
  • Windows 10 AOO, LOLinux Mint AOO, LO
fuzzyluzzi
Posts: 22
Joined: Wed Feb 26, 2014 12:37 pm

Re: [Solved] Open Base Report from Writer

Post by fuzzyluzzi »

Thanks. That opened it perfectly. Would it be possible to modify this macro to automatically save/export the report or should I do that from inside the report?
OpenOffice 4.0.1 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Open Base Report from Writer

Post by Villeroy »

It's a Writer document. Click the PDF button on the standard toolbar.
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
Post Reply