i

Exécuter une requête à l'aide d'une macro


>> voir db_prospect, formulaire "prospects par métier"


sub onClickButton( oEvent as object )


'"Query1" = le nom de la requête


      openQueryDataView( "Query1", oEvent.Source.Model.Parent.ActiveConnection )


end sub


sub OpenQueryDataView( aQueryName as string, aConnection as variant )


    dim oDesktop, oDispatchObject

    dim aURL as New com.sun.star.util.URL

    dim aProps(5) as New com.sun.star.beans.PropertyValue


    oDesktop = createUnoService("com.sun.star.frame.Desktop")


    aURL.Complete = ".component:DB/DataSourceBrowser"


    oDispatchObject = oDesktop.queryDispatch(_

                        aURL, _

                        "_Blank",_

                        com.sun.star.frame.FrameSearchFlag.CREATE)


    aProps(0).Name = "ActiveConnection"

    aProps(0).Value = aConnection

    aProps(1).Name = "CommandType"

    aProps(1).Value = com.sun.star.sdb.CommandType.QUERY

    aProps(2).Name = "Command"

    aProps(2).Value = aQueryName

    aProps(3).Name = "ShowMenu"

    aProps(3).Value = TRUE

    aProps(4).Name = "ShowTreeView"

    aProps(4).Value = FALSE

    aProps(5).Name = "ShowTreeViewButton"

    aProps(5).Value = FALSE


    oDispatchObject.dispatch(aURL, aProps)


end sub