Use macro to autofill field

Hello all,

I am trying to autofill a field in a form while adding data.

In my table I have the following field names:
First name
Last name
second person
second first name
second last name

While adding data to my table using a form, I would like the form to autofill the “second person” field with a standard value of “and”.

The end result would be:
first name last name and second first name second last name

I then want to use this data to print labels for sending mail.

searching for solutions I encountered something like:

sub add_second_person (PysEvent)
if PysEvent.Source.text <> "" then  PysEvent.Source.getByName("txtSecond Person") = "and"
end sub

Of course this does not work at all :stuck_out_tongue:
I know I have to define the getByName as a variable. Unfortunatly I don’t know how.

I have been reading the LibreOffice macro manual. But still no idea of how to pull this off.

Hope anyone can help me with this.

Many thanks in advance.

Tinus087

figured it out.

the macro helped me do it. I’m not sure if this is the best way to do it but it works fine.

sub add_second_person

dim odoc as object
dim odrawpage as object
dim oform as object
dim osecond_person as object
dim osecond_first_name as object

odoc = thisComponent
odrawpage = odoc.drawpage
oform = odrawpage.forms.getByName("Main Form")
osecond_person = oform.GetByName("txtSecond Person")
osecond_first_name = oform.GetByName("txtSecond Firstname")

if osecond_first_name.text = "" then  osecond_person.text = "" else if osecond_first_name.text <> "" then osecond_person.text = "and"

end sub

It was a pain in the butt, but I finaly figured it out myself. Hope I can help everyone who has the same problem.

Kind regards,

tinus087