| View previous topic :: View next topic |
| Author |
Message |
rancor General User

Joined: 21 Nov 2006 Posts: 28
|
Posted: Tue Jun 26, 2012 5:38 am Post subject: [SOLVED] Open a report from a form button using a filter. |
|
|
Hi,
I'm trying to figure out how to open a report from a Form (using a button/macro) such that the report opens with a filter based on what is selected on the form.
On my form I have a table called tbProjects. In that table is ProjID field. So if I have a particular project entry selected in the table I want to open my report (which is query driven) such that only entries with the ProjID selected in the form are showing. I'm able to open the report using:
| Code: | | ThisDatabaseDocument.ReportDocuments.getByName("MyReport").open |
But, I don't know how to grab the current focused ProjID from the form. Nor do I know how to open the report using that selcted ProjID as a filter on the report. Any suggestions? I'm running LO3.4.3 which use the new report engine.
thanks
Last edited by rancor on Thu Jul 05, 2012 2:10 pm; edited 1 time in total |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
|
| Back to top |
|
 |
rancor General User

Joined: 21 Nov 2006 Posts: 28
|
Posted: Thu Jul 05, 2012 8:13 am Post subject: |
|
|
getByName does not appear to have .filter method that I can apply to the new report engine. This link gives examples for opening forms with filters. If I try to apply to my case:
| Code: | oReport = ThisDatabaseDocument.ReportDocuments.getByName("MyReport")
oReport.open
oReport.filter="( ""tbProjects"".""ProjID"" = " & ProjectID & " )"
oReport.ApplyFilter=True
oReport.Reload() |
I get basic runtime error property or method not found: filter. |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
|
| Back to top |
|
 |
rancor General User

Joined: 21 Nov 2006 Posts: 28
|
Posted: Thu Jul 05, 2012 2:08 pm Post subject: [SOLVE] |
|
|
OK I see I was following the wrong example (Open_Forms_Filtered). This worked based on your openReport function and the example:
| Code: |
Sub OpenProjectReport (oEvent As Object)
dim oButton,oForm
dim oConnection,oReportsDocuments
oButton=oEvent.source.model
oForm=oButton.parent
oConnection=oForm.Activeconnection
oReportsDocuments=oConnection.parent.DatabaseDocument.ReportDocuments
RptName = "MyReport"
ProjID=oForm.getByName("ProjectTable").getByName("ProjID").value
Filter="( ""tbProjects"".""ProjID"" = " & ProjID & " )"
openReport(oConnection, oReportsDocuments, RptName, Filter)
End Sub
|
Thanks for the help. |
|
| Back to top |
|
 |
rancor General User

Joined: 21 Nov 2006 Posts: 28
|
Posted: Fri Jul 06, 2012 10:57 am Post subject: New Error |
|
|
OK so now all was working well on one computer, then all other systems so far are giving this error:
| Quote: | BASIC runtime error.
An exception occurred
Type: com.sun.star.io.IOException
Message: C:/lo-3-4/clone/compnents/package/sourc/xstor/xstorage.cxx:2625;.
|
when they get to this line:
| Code: |
oReportDesign=oReportsDocuments.loadComponentFromURL(aReportName ,"",0,aProp())
|
All are windows systems are running LO3.4.5.
Any ideas what is going on? |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Fri Jul 06, 2012 12:08 pm Post subject: |
|
|
Hello
I have no idea about your problem but it is possible that you not installed the sun/oracle report builder. As far I knew the code you use from the example is only working with the Sun/Oracle reportbuilder.
Romke _________________ OOo 3.4.5 on openSUSE 12.1
Use this forum : http://user.services.openoffice.org/en/forum |
|
| Back to top |
|
 |
rancor General User

Joined: 21 Nov 2006 Posts: 28
|
Posted: Fri Jul 06, 2012 1:02 pm Post subject: |
|
|
Yes I can open the full report no problem on all systems (I've tried 5 systems now).
It appears to be related to JRE. On the system that was working I have four versions of Java runtime listed. "Use a Java..." is selected but none of the versions listed are selected. Runs no problem.
I then try each one separately and I get the error. Now that I have done this there appears to be no way to get back to the state where none of the javas were selected such that the macro worked without error. I have tested JRE's from 1.6.0_04 to 1.7.0_04 none are working.
I have an Ubuntu 12.04 box but can't get reports to open (it's complaining about a missign librptlo file). |
|
| Back to top |
|
 |
rancor General User

Joined: 21 Nov 2006 Posts: 28
|
Posted: Fri Jul 06, 2012 1:33 pm Post subject: Tail chasing |
|
|
OK. I was wrong it appears to be a problem with file being readonly in all the test cases where it did not work. We keep the database frontend in a document vault (back end is MySQL) such that file is readonly unless you have the exclusive lock to it, which you should only need if you are modifying the frontend. So if the LO office file is readonly you can't open the report in Design mode. I'm guessing this is related to these lines:
| Code: | aProp(2).Name = "OpenMode"
aProp(2).Value = "openDesign" |
If I change the .Value to just "open" I get around that error but then I can't set the filter. So this is an inherent problem with having file be readonly.
Any suggestions? For example is there anyway to include a variable criteria in the driving query (like "=:projID") and then have the macro push that value when opening the report? |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
|
| Back to top |
|
 |
rancor General User

Joined: 21 Nov 2006 Posts: 28
|
Posted: Fri Jul 06, 2012 2:34 pm Post subject: |
|
|
I'm not sure how to use the UpdateDocMode=0 that you point out. If this was a Form the .filter= and .ApplyFilter=True would work fine. Seems like that should be a built in feature, maybe I'll post a bug report on that.
Here is one truly horrible (clever but doesn't work for client server app) solution I found:
http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=26040 |
|
| Back to top |
|
 |
|