Populate table control via Macro

I’ve been looking everywhere but I can’t seem to find anything about this.
I have a table control named “tblAllCommodities” and I’m trying to populate its rows via macro. Here’s what I have so far:

		
	Context = CreateUnoService("com.sun.star.sdb.DatabaseContext")
	Db = Context.getByName("new project")
	Conn = Db.getConnection("","") 

	strSQL = "SELECT * FROM [Commodities]"
        Stmt = Conn.createStatement()
        AllCommoditiesQuery = Stmt.executeQuery(strSQL)
        AllCommoditiesQuery.next()

	Dim tblAllCommodities as Variant

	tblAllCommodities = mainForm.getByName("tblAllCommodities")
	tblAllCommodities.data = AllCommoditiesQuery

Or maybe something like this is not possible via macro?
Thank you for your help.

Additional details:
-Certain high-level instructions restrict me from just simply binding the form to a query.
-The main objective is that the table control that I wanted to be filled with data, gets filled by a macro upon start of document.

============================
Version: 7.3.5.2 (x86) / LibreOffice Community
Build ID: 184fe81b8c8c30d8b5082578aee2fed2ea847c01
CPU threads: 4; OS: Windows 10.0 Build 19044; UI render: Skia/Raster; VCL: win
Locale: en-US (en_PH); UI: en-US
Calc: CL

Hello,
Please explain the purpose. Why not just set the form to the Query?
.
If it is a subset of something already on the form the how about a subform?
.
Further details about what you want to accomplish will help.

Certain high-level instructions restrict me from just simply binding the form to a query.
The main objective is that the table control that I wanted to be filled with data, gets filled by a macro upon start of document.

Thank you for letting me make my question to become better.

@hadjiamit
There is no method I know of to “populate” a table control (except current row - again attached to somthing). It is populated from a table, query or SQL in the form.
Do not understand why you believe this is not filled at the start of the document if designed with the Query installed unless this may be variable (not stated as such).
.
You can do this by moving a Table name, query name or SQL into the form along with the type using code. Brief sample here → Is it possible to perform a macro that inserts an SQL command into a Form table? - #2 by Ratslinger

1 Like

A table control does not have any record set. The table control’s FORM provides the record set. A table control is a bundle of single controls (text numeric, listbox, date etc). There is one control for each column and the table control displays one instance per row for each column control.

1 Like