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
'----- 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