Hello,
You stated:
In the line “oReport.commandType = 2” the message “Property or method not found: commandType” appears. What should I do?
Best to start learning MRI or XRay object inspector.
The problem here is that at:
oReport = oDatabaseDocument.reportdocuments.getbyname("MyReport")
There is no commandType
or command
property at this point.
These properties are available when the report is in the edit mode. You can edit the report with a macro but not through the connection you have. For this you should have the object sent from the form. Have given basics of this before.
Tested with:
Sub sendObject
if IsNull(ThisDatabaseDocument.CurrentController.ActiveConnection) then
ThisDatabaseDocument.CurrentController.connect
endif
LimparCampos2(ThisDatabaseDocument)
End Sub
Then the code in MyMacros (guessing that is entire objective here):
Sub LimparCampos2(oDBdoc) As Object
oReport = oDBdoc.reportdocuments.getbyname("MyReport")
oRDesign = oReport.openDesign
oContainerWindow = oRDesign.getCurrentController().getFrame().getContainerWindow()
REM Can set design to minimized or not Visible
REM oContainerWindow.IsMinimized = True
REM oContainerWindow.IsMinimized = False
oContainerWindow.setVisible(False)
REM oContainerWindow.setVisible(True)
oRDesign.CommandType = 2
oRDesign.Command = "YOUR SQL HERE"
oReport.open
oReport.close(True)
End Sub
You should add DIM statements. Design mode closes at end of sub but report itself stays open. Report design remains as before processing.
Edit 2021-07-10:
Recalled access method using your original connection (had done this on a standalone Writer form):
Sub OpenRpt
sDBName = "DB Name Or Location"
oContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
oDB = oContext.getByName(sDBName)
dbForms = oDB.DatabaseDocument.ReportDocuments
oConn = oDB.getConnection("","")
ReportName = "Report Name"
Dim pProp(1) As New com.sun.star.beans.PropertyValue
pProp(0).Name = "ActiveConnection"
pProp(0).Value = oConn
pProp(1).Name = "OpenMode"
pProp(1).Value = "openDesign"
REM Open in Design to modify
oReport = dbForms.loadComponentFromURL(ReportName, "_blank", 0, pProp())
oContainerWindow = oReport.getCurrentController().getFrame().getContainerWindow()
REM oContainerWindow.IsMinimized = True
REM oContainerWindow.IsMinimized = False
oContainerWindow.setVisible(False)
Rem oContainerWindow.setVisible(True)
oReport.CommandType = 2
oReport.Command = "YOUR SQL"
Dim pProp2(1) As New com.sun.star.beans.PropertyValue
pProp2(0).Name = "ActiveConnection"
pProp2(0).Value = oConn
pProp2(1).Name = "OpenMode"
pProp2(1).Value = "open"
REM Open while Design not yet closed - has SQL
oReport2 = dbForms.loadComponentFromURL(ReportName, "_blank", 0, pProp2())
oReport.getCurrentController().getFrame().Close(True)
End Sub
Still requires editing report but now uses your original connection code.