I misunderstood your question.
You want ONE ListBox “B” to select parameter for query (not a ListBox) “A”.
It’s it?
If so it’s simpler: collect the parameter from LB “B” via the
oLBB.current value
and compose the query and run it via code
or (I think better for your case)
alter a saved “QueryA” inserting this parameter on it. And then open it via code.
Code below does this.
You save “QueryA” placing ? as the parameter.
Code:
- It places the parameter as a constant in the saved query.
- Opens (runs) the query in the GUI grid.
- Resets the query (re)placing ? au lieu of parameter.
But first see @Villeroy 's method with Filter Table.
It can be more convenient to your case.
Option Explicit
Sub Consulta(evt As Object)
Dim Formulario As Object, LBAnos As Object, Con As Object, QD As Object
Dim ano As Integer
Dim sSQL As String
Formulario = evt.Source.Model.Parent
LBAnos = Formulario.getByName("lbAnos")
ano = LBAnos.CurrentValue
REM THE CONNECTION
Con = Formulario.ActiveConnection()
QD = Con.Queries.getByName("TheQuery")
sSQL = QD.Command
sSQL = Replace(sSQL, "?", ano)
MsgBox sSQL
QD.Command = sSQL
REM OPEN THE PARAMETRIZED QUERY
OpenQuery("TheQuery")
REM RESET THE QUERY
sSQL = Replace(sSQL, ano, "?")
QD.Command = sSQL
End Sub
REM TO OPEN A QUERY
Sub OpenQuery(query As String)
Dim TipoObjeto
TipoObjeto = com.sun.star.sdb.application.DatabaseObject.QUERY
ThisDatabaseDocument.CurrentController.loadComponent(TipoObjeto, query, FALSE)
End Sub