Ask Your Question
0

use macro to autofill field [closed]

asked 2015-11-05 19:07:12 +0200

tinus087 gravatar image

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 :P 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

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 2016-03-15 00:33:05.252174

1 Answer

Sort by » oldest newest most voted
0

answered 2015-11-06 14:45:59 +0200

tinus087 gravatar image

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

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-11-05 19:07:12 +0200

Seen: 530 times

Last updated: Nov 05 '15