Problem loading a report

Discuss the database features
Post Reply
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Problem loading a report

Post by arfgh »

I just used the little code ahead to reload the current report document:
dim rp as object
rp = ThisDatabaseDocument.ReportDocuments.getByName(getDocTitle)
rp.close()
rp.open()
... and works fine, but not if we place the report into a folder. In fact i dont know how to load a report from basic, when it is located into a folder.
Help.

thx in advance
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Problem loading a report

Post by Villeroy »

Use MRI :!:
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
UnklDonald418
Volunteer
Posts: 1548
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Problem loading a report

Post by UnklDonald418 »

i dont know how to load a report from basic, when it is located into a folder.
As Villeroy suggested, if you use the MRI tool you should be able to see that accessing a report in a folder works just like accessing a subForm from a Form.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: Problem loading a report

Post by arfgh »

ok, but some tip will be welcome.
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
UnklDonald418
Volunteer
Posts: 1548
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Problem loading a report

Post by UnklDonald418 »

Since you didn't seem to understand the hint I gave how about a lesson in using the MRI tool.
Assuming you have installed and enabled the MRI extension.
Near the beginning of your macro insert the following code to make sure the MRI tool is available inside your macro (the MRI library is loaded and the UNO service is started)

Code: Select all

If Not Globalscope.BasicLibraries.isLibraryLoaded("MRILib") Then
      Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
End If
oMRI = CreateUnoService( "mytools.Mri" )
Using ThisDatabaseDocument directly in macro statements can be risky. While it isn't likely to be an issue in your little macro you should get in the habit of assigning it with something like

Code: Select all

oDoc = ThisDatabaseDocument
using oDoc throughout the remainder of the macro is safer. Your assignment of “rp” becomes

Code: Select all

rp = oDoc.ReportDocuments.getByName(getDocTitle) 
Insert the following statement after you have assigned “oDoc” and before you assign “rp”

Code: Select all

oMRI.inspect oDoc
Open the IDE (<Alt> F11). Locate your macro and select Edit. Set a breakpoint on the line “rp = oDoc.ReportDocuments.getByName(getDocTitle)” and then click on the Run icon.
Execution should stop at the line with the breakpoint and you should also now see a MRI dialog.
By default the MRI dialog opens with the Properties tab selected.
Scroll through the list of properties and select “ReportDocuments”
Now select the Methods tab in the MRI dialog.
Scroll through the list of methods and select “getByName”.
You should get a popup list of items in the main Reports folder. One of those items should be the name of the Folder where your report is stored. Select that item.
Scroll through the methods list and again select “getByName”. A new list should popup this time your report name should be on the list. Select that item.
If it hasn't occurred to you what needs to changed in your macro press <Ctrl> h and a new pane should open at the bottom of the MRI dialog. It displays the code used to access your report. You can copy this code into the clipboard.
In the IDE stop the macro execution. Paste the contents of the clipboard into your macro.
Finally, edit the “rp” assignment in include the inserted code.
You can either delete the lines of code used to access the MRI tool or better yet change them to comments in case you need them at some future date.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Problem loading a report

Post by Villeroy »

Activate your database window.
Tools>Add-Ins>Mri. Now you see all properties and methods of the active document.
Maximize the MRI window.
Double-click property "ReportDocuments". Now you see all properties and methods of the reports collection.
Double-click method getByName and choose the name of the folder. Now you see all properties and methods of the folder.
Double-click method getByName and choose the name of the report. Now you see all properties and methods of the report.

Alternative path to the members of a folder:
Use the [<] button or the list box in order to go back to the ReportDocuments
Double-click method getByHierarchicalName and enter "Folder1/MyReport" (with actual names of folder and report)

Finally hit Ctrl+H and enjoy the code. It is also availlable in C++, Java and Python

Code: Select all

Sub Snippet
  Dim oReportDocuments As Variant
  Dim oObj1 As Variant
  Dim oObj2 As Variant
  Dim oObj3 As Variant

  oReportDocuments = ThisComponent.getReportDocuments()
  oObj1 = oReportDocuments.getByName("Folder1")
  oObj2 = oObj1.getByName("qFiltered")
  
  oObj3 = oReportDocuments.getByHierarchicalName("Folder1/qFiltered")

REM added by Villeroy:
REM oObj2 is the same object as oObj3
REM which can be proved with a Basic function
print EqualUnoObjects(oObj2, oObj3)
End Sub
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
arfgh
Posts: 566
Joined: Tue Mar 05, 2013 6:44 pm

Re: Problem loading a report

Post by arfgh »

thx so much UnklDonald418 for such effort you did on your post :)
I go to mess with the MRI, now knowing how to start thx to you.
Surely will help me much with basic procedures, etc.

thx
OpenOffice last version | Mageia Linux x64 | Ubuntu Linux | Windows 8.1 Enterprise x64 | Java last version
Post Reply