Use a choice from a drop-down sourced from a query as a query parameter

Sorry for having to ask this but I have looked at lots on content without being able to understand how to do this.

I have a query ‘A’ with a parameter that selects a subset of results by filtering against a field ‘X’.
I have a query ‘B’ that lists all unique values for field ‘X’.

What I want to do is have drop-down of the result of query ‘B’ and to select a value from the drop-down to use as the parameter in query ‘A’.

Presumably a combination of sub-forms, combo boxes etc. but I cannot see how to do it.

Have neither LO nor a dummy DB in this machine to check. But I think you could try setting the “ListBoxA” ListSource:

Sub SetA(evt As Object)
    Dim oLBA As Object, oLBB As Object
    Dim sSQL(0) As String ' it must be an array I think
    Dim x As String ' for the X parameter
    [...]
    ' collect x = the selected value from "ListBoxB"
    ' compose query A:
    sSQL = "SELECT [...] WHERE ""the_field"" = '" & x & "'"
    oLBA.ListSource = sSQL
    oLBA.refresh
End Sub

Just speculative: don’t know if this will work!
Please see

Listbox in table control: change ListSource property w/ macro?

https://ask.libreoffice.org/uploads/short-url/gK9hcyzEnMVotx6Mtmr6CqCDsPR.odb