Base: run a query with a variable?

I have a Form of a “query” type, and that query asks for a :variable. I want to write a macro that passes something as that variable when refreshing that form. Is that possible?

While we’re at it, is it possible to write a macro to execute another query from the same project and pass a variable to it?

I am trying to read the manual, which has something about establishing connections with databases and running queries, but that doesn’t look like what I want. I just want to call a query that’s already in the project I’m working with, one that might even be associated with the form this macro is being run from! Is there no simple way to, like, result=ThisProject.PredefinedQueries.getByName(“MyQuery”).Execute?!..

Here is a way to access the stored query definition and run it indirectly. In this example, the entire LibreOffice file object is named New Database.odb.

DB=Context.getByName("New Database") 
Queries = Db.getQueryDefinitions()
sql_str = Queries.getByName("Query1").command

root_form = ThisComponent.Drawpage.Forms
mainform = root_form.getByIndex(0)
conn = mainform.ActiveConnection
sql = conn.createStatement()

result = sql.executeQuery(sql_str)
MsgBox result.getString(1)

This will return a message box with the first column of the first row of the query, assuming it is a string. If you explore the object Queries.getByName("Query1") with dbg_methods and dbg_properties, you might find a way to run the query directly. If you explore result in the same way, you will see the other methods to return row contents. Every data type has its own method. The code is intended to be run from a form.