[Solved] Button to show report

Getting your data onto paper - or the web - Discussing the reports features of Base

[Solved] Button to show report

Postby robert leleu » Fri Jul 03, 2015 6:14 pm

A form has 2 buttons
    one activate another form using this macro
    Code: Select all   Expand viewCollapse view
    Sub ouvre_liens
    ThisDatabaseDocument.FormDocuments.getByName("liens").open
    End Sub

    the other...doesn't open a report although using a similar macro
    Code: Select all   Expand viewCollapse view
    Sub ouvre_adresses
    ThisDatabaseDocument.ReportDocuments.getByName("Adresses").open
    End Sub

However this second macro, when activated from the macro menu does open the report

If someone has an idea....

thanks
Last edited by robert leleu on Sat Jul 11, 2015 11:50 am, edited 1 time in total.
libreoffice 4.2.8.2
Linux Mint 17 Rebecca
robert leleu
 
Posts: 11
Joined: Fri Jul 03, 2015 5:49 pm

Re: Button to show report

Postby Nocton » Sun Jul 05, 2015 2:31 pm

doesn't open a report

OK, but what does happen? Is there an error message?

Regards,

Nocton
OpenOffice 4.2.0 on Windows 10
Nocton
Volunteer
 
Posts: 495
Joined: Fri Nov 05, 2010 10:27 am
Location: UK

Re: Button to show report

Postby robert leleu » Sun Jul 05, 2015 3:29 pm

The main query of the form is loaded up to the last line, and the pressed button lays inactive.

Note that the brother button to open a form returns to active position
libreoffice 4.2.8.2
Linux Mint 17 Rebecca
robert leleu
 
Posts: 11
Joined: Fri Jul 03, 2015 5:49 pm

Re: Button to show report

Postby Nocton » Sun Jul 05, 2015 3:48 pm

I do not know what the problem is, maybe the database connection has failed. But below I give Basic code, developed mostly from input on this board, that I have used for several years to call a report from a form button. (The code may look complex, but it works and allows the report to be set in the button's properties rather than in a macro).
Now just assign the 'Mouse button released' event to CreateReportCalledfromButton and in the button's 'Additional Information/Tag' property put the name of your report.
Just click on the button and your report will open.

Regards,
Nocton
Code: Select all   Expand viewCollapse view
'----- suite to open any report
Sub CreateReportCalledfromButton(oEvent as object)
' We need this sub for a button in a standalone form
    dim oCreateButton,oForm ' This are form details
    dim oConnection,oReportsDocuments
' The connection we need for finding the database document
    oCreateButton=oEvent.source.model

    if oCreateButton.tag = "" then
       msgbox "No report name in the button tag" & chr(13) & "This is the third from below of the property on the common tabpage"
    else ' Now we have to start to find all kind of objects
       oForm=oCreateButton.parent
'      if oForm.filter="" then
'         print "You have no filtered data in your form"
'      else
          oConnection=oForm.Activeconnection
          oReportsDocuments=oConnection.parent.DatabaseDocument.ReportDocuments ' This point to the report containers
          ' Test if the name exists
          if oReportsDocuments.hasByHierarchicalName(oCreateButton.tag) then
             'Call openreport with the parameters
             openReport(oConnection, oReportsDocuments, oCreateButton.tag , oForm.Filter)
          else print "There is a wrong report name"
          end if
'       end if
    end if
End Sub

Function openReport(oConnection, oReportsDocuments,aReportName,sFilter) as object
' The document you want to call must be:
'   a)in the databasedocument from this connection.
'   b) The document must be a report
       
' Make the array we use in both commands
       dim aProp(2) as new com.sun.star.beans.PropertyValue
       dim aProp2 ' Make a variant
       dim oReportDesign
       aProp(1).Name = "ActiveConnection"
       aProp(1).Value = oConnection
       aProp(0).Name = "Hidden"
       aProp(0).Value = true   
       aProp(2).Name = "OpenMode"
       aProp(2).Value = "openDesign"
       let aProp2=aProp 'assign the array. The reason it is possible that the values
       ' are changed when I use it in loadComponentFromURL
       'Open report in design mode and hidden
       oReportDesign=oReportsDocuments.loadComponentFromURL(aReportName ,"",0,aProp())
       ' oReportDesign.filter=sFilter ' Change the filter
       
       ' Two Values must be changed
       aProp2(0).Value = false
       aProp2(2).Value = "open"
       ' Now the result of the report will be shown and the the hidden report in design mode is closed
       openReport=oReportsDocuments.loadComponentFromURL(aReportName ,"",23,aProp2())
End Function 
OpenOffice 4.2.0 on Windows 10
Nocton
Volunteer
 
Posts: 495
Joined: Fri Nov 05, 2010 10:27 am
Location: UK

Re: Button to show report

Postby robert leleu » Sun Jul 05, 2015 4:37 pm

Merci.

However I put your code in a macro. I see no other place to put it.

My final aim is to print the report for one selected line of the main query (for instance using the autofilter) but once the line selected by this way the button is inactive.
Moreover the displayed report cannot be closed from its menu. One has to close the whole odb.

Cordialement
libreoffice 4.2.8.2
Linux Mint 17 Rebecca
robert leleu
 
Posts: 11
Joined: Fri Jul 03, 2015 5:49 pm

Re: Button to show report

Postby Nocton » Mon Jul 06, 2015 9:33 am

The code works very reliably, but of course only prints the report as you have it in the way it would print if run directly.
My final aim is to print the report for one selected line of the main query (for instance using the autofilter)


I do not understand what you mean by this statement. On another thread which I have replied to https://forum.openoffice.org/en/forum/viewtopic.php?f=42&t=77686&sid=3a43f9681349f5fc2dbd0c2b0951d4c5&p=356780#p356780 I have explained how to print a single record - if that is what you are trying to do.

Regards,

Nocton
OpenOffice 4.2.0 on Windows 10
Nocton
Volunteer
 
Posts: 495
Joined: Fri Nov 05, 2010 10:27 am
Location: UK

Re: Button to show report

Postby robert leleu » Mon Jul 06, 2015 4:48 pm

Merci


rewording : there is a list on the form. I select one line, and want to print the report with the datas of this line

The link you gave is well adapted, however I don't find (or understand) how to use the 4th line which is :
4. On main form set up 'FilterForm' subform with data source FilterID table and with text box 'fldGroupID' with data field set to selected/filter ID.

My form has yet a subform and I don't see how to add another one.
and from searching I think that it's just impossible, since the only way to build a form including one subform (but only one) is to use the wizard.

I try to rearrange the whole application.

Cordialement
libreoffice 4.2.8.2
Linux Mint 17 Rebecca
robert leleu
 
Posts: 11
Joined: Fri Jul 03, 2015 5:49 pm

Re: Button to show report

Postby Nocton » Mon Jul 06, 2015 6:32 pm

Forms can have as many subforms or subsubforms as you wish:
1. Show the Form Design Toolbar (View->Form Design).
2. Click on Form Navigator to show forms and controls.
3. Right-click on form that you wish to create a subform and select New->Form.
4. Link Master and Slave fields as required

You can now easily create new controls, text boxes, etc. on the new subform or move a control from one form to another.
Regards,

Nocton
OpenOffice 4.2.0 on Windows 10
Nocton
Volunteer
 
Posts: 495
Joined: Fri Nov 05, 2010 10:27 am
Location: UK

Re: Button to show report

Postby robert leleu » Mon Jul 06, 2015 10:18 pm

thanks
Tried successfully
libreoffice 4.2.8.2
Linux Mint 17 Rebecca
robert leleu
 
Posts: 11
Joined: Fri Jul 03, 2015 5:49 pm


Return to Reporting

Who is online

Users browsing this forum: No registered users and 0 guests