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 "fullnaam" FROM table; 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 "fullnaam" FROM table;
.
Maybe you will need
SELECT COALESCE ("naam", '')|| COALESCE(' '||"vornaam", '') AS "fullnaam" FROM table;
.
Sorting is another question. Depends on your “abnormal alphabetical ordering”., and if your database supports different collation.