We're currently migrating from Ask to Discourse, read the details here

Ask Your Question

Table Controls, Reading and Writing to Columns via Macro [closed]

asked 2018-11-07 02:43:30 +0200

PhLo gravatar image

updated 2021-06-10 22:31:35 +0200

Alex Kemp gravatar image

I wrote a very handy macro for Base that copies an array of fields from one form to another. It works no matter if the form is at the highest level, a sub form, or a sub-sub form, etc. However, it completely fails when I try to access forms represented by a table control (as opposed to separate fields). Some people call table controls "grid controls" where there are rows and columns of data representing your records.

Is there a special method or object I must use to access data displayed in a table control that differs from separate form fields?

As a quick example, normally to read the value from a field I do something like this:


And to write to the same field I would do something like:

thisComponent.drawpage.forms.getByName("form").getByName("subForm").getByName("subSubForm").getByName("fieldName").boundField.updateString("some value")

This always works for regular, separate fields. If, however, there is a table control (aka grid) as the final destination/source, nothing works. So I'm guessing there is a special object dealing with table controls. Do I need to add an extra step in the hierarchy navigation .getByName("tableControlName") ? I tried that, and it still didn't work. Are .currentValue and .boundField.getString() (or .getXXX other type) not the right methods for table control columns? They work for regular fields every time.

I can't find any documentation or questions answered here relating to table controls and how to read/write their column values within macros. I thought it was the same as with other fields, but I'm hitting a roadblock.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2021-06-10 22:31:49.468506


Trying to access a table column field as described above, I get the following error no matter what I try... BASIC runtime error. An exception occurred. Type: com.sun.star.container.NoSuchElementException Message: . In fact, many times it completely crashes Base, and I have to recover my document.

PhLo gravatar imagePhLo ( 2018-11-07 02:53:14 +0200 )edit

I feel like there could be an error in my code or something. If so, then I'll probably figure it out. If not, then who knows. I'll keep hunting.

PhLo gravatar imagePhLo ( 2018-11-07 03:28:27 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-11-07 03:28:05 +0200

Ratslinger gravatar image

updated 2018-11-07 03:39:53 +0200


When dealing with individual fields you are dealing with a single record. With a table control there are multiple records available, so first go to the wanted record:

  oDrawPage = ThisComponent.getDrawPage()
  oForms = oDrawPage.getForms()
  oObj1 = oForms.getByName("MainForm")
Rem Get record wanted  
  oObj2 = oObj1.absolute(3)

When you have the wanted record, the easiest way to insert data is using Columns. So if I want to place data in the field named COLOR2 then:

Rem Get column you are dealing with
  oColumns = oObj1.getColumns()
  oObj3 = oColumns.getByName("COLOR2")
Rem Update field with type data used - this is a varchar field  

Then just insert or update row.


Grid controls ARE different. See my post here -> Looking to create grid (not table) control on Base form

edit flag offensive delete link more


Awesome. That sounds promising. Thanks, I'll try it out.

PhLo gravatar imagePhLo ( 2018-11-07 03:33:58 +0200 )edit

Still can't solve this nonsense, but I'm going to accept your answer anyway because it's good for others to see. With all this weird behavior and confusing methods, I'm half wondering if I could hand-coded a web interface from scratch using web technologies in less time. boo. VB type languages are very, very odd.

PhLo gravatar imagePhLo ( 2018-11-07 08:41:52 +0200 )edit

There is a lot to understand when dealing LO and the Uno API. I realize my sample does not explain the details. This is where the docs are important in understanding a lot of the basics in controls & data manipulation. It is certain I failed to make clear that the field name used in the sample is that of the table field and not of the table control.

Yes, you can do a lot of things faster using something you already understand. Everything takes time to learn, even what you already know.

Ratslinger gravatar imageRatslinger ( 2018-11-07 18:12:16 +0200 )edit

Agreed. I hoped Base would provide me a low-code interface that is easier to maintain than having to hand-code everything in PHP, HTML, Javascript & MySQL. Connecting controls to data is easy in Base, but much other functionality is lacking. Obviously macros can overcome the shortcomings, but to make it work requires quite advanced macro knowledge. I'm worried I'll get it working, but later a LO update will break everything, and I won't be able to maintain the code anymore :(

PhLo gravatar imagePhLo ( 2018-11-08 03:34:20 +0200 )edit

I wish there was better documentation of every function in the LO Basic macro language. I have been scouring the web and the known resources and can't find a thorough description of what methods and functions are available. The functions I want to use are barely mentioned if at all in the known resources, so I can't get a handle on how they work. Sample code for every function is a must! The PHP website is AMAZING for this. Too bad LO doesn't have such a thing (if they do, I don't know where).

PhLo gravatar imagePhLo ( 2018-11-08 03:36:53 +0200 )edit

Here is probably another source which you will cringe at -> Apache OpenOffice Developer's Guide. It contains a lot of the ifs, ands and wherebys. It saved me many a time. Like the others, a LOT of delving into to get anywhere.

Ratslinger gravatar imageRatslinger ( 2018-11-08 03:49:25 +0200 )edit

Hey, anything is better than nothing. I'm bookmarking every single thing you guys point at in case there are nuggets for me to discover. I much appreciate it. And even though my responses sound a little frustrated, I'm not giving up yet. I'm pretty determined to get this thing working.

PhLo gravatar imagePhLo ( 2018-11-08 09:48:27 +0200 )edit

Question Tools

1 follower


Asked: 2018-11-07 02:43:30 +0200

Seen: 1,807 times

Last updated: Nov 07 '18