[Solved] Open Base Report from Writer

Discuss the database features

[Solved] Open Base Report from Writer

Postby fuzzyluzzi » Thu Mar 26, 2015 12:35 pm

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   Expand viewCollapse view
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
fuzzyluzzi
 
Posts: 22
Joined: Wed Feb 26, 2014 12:37 pm

Re: Open Base Report from Writer

Postby Villeroy » Thu Mar 26, 2015 4:06 pm

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   Expand viewCollapse view
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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26870
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open Base Report from Writer

Postby fuzzyluzzi » Fri Mar 27, 2015 6:38 am

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
fuzzyluzzi
 
Posts: 22
Joined: Wed Feb 26, 2014 12:37 pm

Re: Open Base Report from Writer

Postby Villeroy » Sat Mar 28, 2015 4:09 pm

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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26870
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open Base Report from Writer

Postby F3K Total » Sat Mar 28, 2015 9:02 pm

Villeroy wrote:I'm 90% sure ...

now you can be 100% sure ...
Code: Select all   Expand viewCollapse view
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 7 OOo, AOO, LOLinux Mint OOo, AOO, LO
F3K Total
Volunteer
 
Posts: 913
Joined: Fri Dec 16, 2011 8:20 pm

Re: Open Base Report from Writer

Postby Villeroy » Sat Mar 28, 2015 10:36 pm

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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26870
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open Base Report from Writer

Postby F3K Total » Sat Mar 28, 2015 11:15 pm

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 7 OOo, AOO, LOLinux Mint OOo, AOO, LO
F3K Total
Volunteer
 
Posts: 913
Joined: Fri Dec 16, 2011 8:20 pm

Re: [Solved] Open Base Report from Writer

Postby fuzzyluzzi » Mon Mar 30, 2015 10:35 am

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
fuzzyluzzi
 
Posts: 22
Joined: Wed Feb 26, 2014 12:37 pm

Re: [Solved] Open Base Report from Writer

Postby Villeroy » Mon Mar 30, 2015 12:18 pm

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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26870
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to Base

Who is online

Users browsing this forum: No registered users and 5 guests