How to get selected row from table control (also: refresh the query)?

I need the selected row from a table control in a writer document. Using this, I can see if a row is selected at all:

Option Explicit
Sub GetSelected
Dim oForm As Object
Dim oSelectedRows As Object
Dim oTable As Object
Dim oTableView As Object
Dim iStart As Integer
Dim iEnd As Integer
Dim myTotal As Integer
Dim n As Integer
Dim i As Integer
REM Get access to the current form
oForm = ThisComponent.Drawpage.Forms.getByName(“Today_Roster”)
REM Get Table Grid Control
oTable = oForm.getByName(“available_offenders”)
Rem Get View for Grid Control
oTableView = ThisComponent.getCurrentController().getControl(oTable)
Rem Get array of selected rows
oSelectedRows = oTableView.getSelection()

because the UBOUND of oSelectedRows will be -1 if one is not.

However, after this I can’t figure out how to actually get any data from the control.
image

Also, these tables are based on Base Queries, so after I submit the commands I will need to refresh the tables. For example, I will be submitting a SQL command and base the where clause off the ID of the selected row.

I’d appreciate even a partial answer, it’s probably simple but I can’t implement any logic until I can figure out how to move forward on this.

Note: The macro needs to be executed in writer.

Hello,
There is a sample in this post > SOLVED: Read values from selected rows in a table control .
.
It totals one or more selected lines. The data is obtained by using the View of the control.
.
As for refreshing, just reload() the form.

Hmm, I keep getting errors with that!

It doesn’t seem to like the line:

i = oForm.columns.FSVALUE2.getInt()

It says: Property or method not found: FSVALUE2.

You get the error when pushing the button? Here is my test with that posted file:
Screenshot at 2022-03-28 20-18-30
using:

Version: 7.3.1.3 / LibreOffice Community
Build ID: a69ca51ded25f3eefd52d7bf9a5fad8c90b87951
CPU threads: 8; OS: Linux 5.4; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded

Do not know what you are using - specific LO version or OS.

Oh, I’m sorry. I’ve spent some time testing it, I should have specified… I’m trying to make this work in writer, even though the database is, of course, in LibreOffice base.

No, writer does not seem to know about that property.

A Form is a Form is a Form. This should work in writer if you are using a table control on a form.
.
Need a bit of time (currently doing something else) and will try in a Writer document myself. Do not anticipate any problem.

Not a Writer issue but a form issue. Again this IS a table control you are using isn’t it? And code is in Writer doc not Base or My Macros? And you still have not specified:

.

meaning this is a standalone form?

Yessir. It’s actually totally acceptable to do it in calc: the real goal is that you click it and then this comes up.

It is unrealistic to teach the staff members who need to quickly record this information to navigate libreoffice base. It needs to be click and go from a desktop icon- with or without base.

Sorry but have no idea what your last comment means.
.
Just copied the sample information to a Writer doc - the form, the code & registered the DB. Had to delete & re-draw the Table Control but it works fine with the code copied from the sample:

Okay, so I keep trying this. It says oForm.columns is “out of scope” and when I look at oForm itself, I can’t find any evidence of anything that looks like a column. I confess I didn’t use the example directly, but I did copy and paste. And I deleted and recreated the table within writer.

Seems you are looking for the columns. Columns are an object, which only shows an array of the field names of the table. You could see the content, for example, with the tool xray.
The column name is the name of the field in the data source. So if a form in Writer is connected to a database it will get the names of the fields of a table or query from this database.

Do not understand as scrolling toward the end of the watch window I find:
Screenshot at 2022-03-29 08-15-01
.
The statement in the sample:

 i = oForm.columns.FSVALUE2.getInt()

get the table column (here FSVALUE2) and retrieves the data ( here using getInt()).