Basic error in macro

Pls some help with this.
I have a table “crew” with several fields. I want to concatenate 2 fields in 1 other field (‘naam’ & ‘voornaam’ in ‘nmvnm’) cf. attachment

That works well, then I found a macro in the topics that I adapted to my fields. In the event When losing focus of ‘naam’ en ‘voornaam’ I marked the macro ‘Naamvoornaam’. I saved all of that and the the dbase.

![Scherm­afbeelding 2024-11-23 om 09.23.43|474x500]
(upload://ma3VXl3D2Bk4miBg63PyeZ50EJU.jpeg)

WHen I then open the form and leave the field ‘naam’ after edit, I get an error.

What am I doing wrong?
In the original macro I got the same error but “Forms” was designated as “Drawpage”.

Thx for any support.

Please upload real sample files here, together with the editable macro code.

IMHO: Using a macro for something easily done in a SQL-QUERY

1 Like

Should be:
oForm = ThisComponent.Drawpage.Forms.getByName("f-crew")
Form document is opened and you try to get a from inside the form document.
.
But: Never save data, which is a result of a query. If you change the source for this data the saved result would be wrong.
Example:
"naam" = 'Schulze' "voornaam" = 'Hein' "naam"||' '||"vornaam" = 'Schulze Hein'
You will save ‘Schulze Hein’ by macro as a new content.
Now you heard: ‘Hein’ is wrong, should be ‘Hendrik’. Yo change the “voornaam”. The query will show ‘Schulze Hendrik’, but the new field shows the old ‘Schulze Hein’. Integrity of data has been lost.

I understand, coming from MS Access I only had to concatenate the 2 fields in a new field and the job was done. I need the info for easy mailing and abnormal alphabetical ordering.
Any other suggestions?

@JonIgartua . Why don’t you do it by a query? Seems Access will do it the same as other databases. It won’t create a new field with independent content.

Sure, but the query alone does not work.

?? What is not working?
.
SELECT "naam"||' '||"vornaam" AS "Naamvoornaam" FROM "crew"; can be used as first approach.
.
For Databases you should also consider NULL-value, as concatenating with NULL gives NULL. So we may use IFNULL or COALESCE:
In my database the Name is mandatory not NULL so I use (with , between the two parts):
SELECT "naam"|| IFNULL(', '||"vornaam", '') AS "Naamvoornaam" FROM "crew";
.
Maybe you will need
SELECT COALESCE ("naam", '')|| COALESCE(' '||"vornaam", '') AS "Naamvoornaam" FROM "crew";
.
Sorting is another question. Depends on your “abnormal alphabetical ordering”., and if your database supports different collation.

Robert G probably has your solution… For help on debugging syntax of an object’s methods you can insert LO’s built in debugger “dbg_methods” by inserting into the macro:
oForm = thisComponent
msgBox(oForm.dbg_methods)

At runtime a msgBox will appear giving a list of all the applicable methods for the oForm as thisComponent. Take note of the method desired and close the msgbox by clicking OK or hitting enter (return). Append the noted method to the oForm=thisComponent (…thisComponent.drawPages).
Repeat this process until the desired method is completed, then the msgBox() line may be deleted.
There is also a dbg_properties method which will list the properties of the object. When I was a LO novice, this was much faster and easier than doing an online search, and the methods became like muscle memory.

1 Like