Thank's RPG
Here is the final code
Code: Select all
REM *******************************************************
REM ***** *****
REM ***** CustomerAdressLabel *****
REM ***** *****
REM ***** Filter and prints adresslabels. *****
REM ***** Open the query QueryCustomerAdressLabel, *****
REM ***** changing the underlying SQL-statement *****
REM ***** so it only filters the current post *****
REM ***** and then print the report ReportCustomer *****
REM ***** AdressLabel which is based on the query *****
REM ***** QueryCustomerAdressLabel. Uses the macro *****
REM ***** ExecuteReport to open and print the report. *****
REM ***** *****
REM *******************************************************
Sub CustomerAdressLabel (Event as object)
Dim tblcustomer as object
Dim Controller as object
Dim RepQuery as variant
Dim SQLtext as string
Dim custID as integer
REM oEvent is an EventObject
REM Source is the control that called the event - the button
REM Model is what we use when we want to get to properties avialable at design time
REM Parent is the name of the contol that the button belongs to
tblcustomer=Event.Source.Model.Parent
custID = tblcustomer.getInt(tblcustomer.FindColumn( "customer_id" ))
'xray tblcustomer
ExecuteReport( tblcustomer.ActiveConnection,"QueryCustomerAdressLabel",_
"customer_id = " & custID,"ReportCustomerAdressLabel" )
end sub
REM *************************************************
REM ***** *****
REM ***** ExecuteReport *****
REM ***** *****
REM ***** Macro for printing filtered reports *****
REM ***** *****
REM *************************************************
sub ExecuteReport( aConnection as variant, _
aQueryName as string, _
aFilter as String, _
aReportName )
dim composer as variant
dim oReport as variant
dim aryProp(1) as new com.sun.star.beans.PropertyValue
dim oreport as object
dim printOpts()
REM ---- Creates a SQLQueryComposer object
composer = aConnection.createQueryComposer
REM ---- Creates a new query in the composerobject based on the old query from aConnection.Queries ...
composer.setQuery( aConnection.Queries.getByName( aQueryName ).Command )
REM ---- Sets a filter to the query in the composerobject
composer.setFilter( aFilter )
aryProp(0).Name = "ActiveConnection"
aryProp(0).Value = aConnection
aryProp(1).Name = "OpenMode"
aryProp(1).Value = "open"
REM ---- Open the report
oreport=aConnection.Parent.DatabaseDocument.ReportDocuments.loadComponentFromURL( aReportName, "_blank", 0, aryProp() )
REM ---- Prints the report
oreport.Print(printOpts)
wait 800
REM ---- Close the report-document
odocument.close(true)
REM ---- Put back the old SQL-statement to the query
aConnection.Queries.getByName( aQueryName ).Command = composer.getQuery
end sub
I noticed in the API wiki that DatabaseDocument was deprecated. The devguide suggested using:
XPrintable xPrintable = (XPrintable)UnoRuntime.queryInterface(XPrintable.class, xDoc);
Tried to convert that to starbasic but get a couple of errors (probably due to me being tired). Anyone less tired than me knowing the starbasic syntax?
Zeke