How Do I Create a Form Button to Add a New Record?

Creating and using forms
Post Reply
jdanniel
Posts: 67
Joined: Tue Mar 04, 2008 8:25 pm

How Do I Create a Form Button to Add a New Record?

Post by jdanniel »

Hello.

I'd like to create a button on my form that sets the focus to a particular field, and then opens up a new record for data entry.

Which control should I use for this? And are there pre-designed macros that I can plug into the button for this?

I tried using the Push Button control, but couldn't figure out what to do from there. Is the Push Button control the right one to use?

Thank you! Jd
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How Do I Create a Form Button to Add a New Record?

Post by Villeroy »

Draw a button and set it's "Action" property to "New record". I don't know about the focus.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
probe1
Volunteer
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand

Re: How Do I Create a Form Button to Add a New Record?

Post by probe1 »

Jd,

Villeroy's suggestion sets the focus to the first entry control here.

If you like to set the focus to another control, use the following code [copy it to a module in "My Macros"], adjust the control name [getByName statement], and assign to the "When initiating" event of your pushbutton:

Code: Select all

Sub base_newRecordAndFocus

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:NewRecord", "", 0, Array())

oDoc = ThisComponent
oDocView = oDoc.getCurrentController()

oForm = oDoc.drawpage.forms(0)
oFeld = oForm.getByName("fmtnumwert")

oDocView.getControl(oFeld).setFocus()

End Sub
Works here with OOo 2.4.0rc6-de 2008-03-14
Cheers
Winfried

DateTime2 extension: insert date, time or timestamp, formatted to your needs
jdanniel
Posts: 67
Joined: Tue Mar 04, 2008 8:25 pm

Re: How Do I Create a Form Button to Add a New Record?

Post by jdanniel »

I've change my mind about something.

I want a separate control button JUST to set the focus to a specific field.

I've created separate push buttons for adding and deleting a record.

Can I create a separate control button that sets the focus to a specific field, without any code? Or do I need code to do that?

I didn't see a SET FOCUS option under Action.

How can I revise your code to do that, if code is, in fact, required? And what part of the code will I have to revise for my form, so it sets the focus to the field of my choice?

Thank you. Jd
User avatar
probe1
Volunteer
Posts: 277
Joined: Mon Oct 08, 2007 1:34 am
Location: Chonburi Thailand

Re: How Do I Create a Form Button to Add a New Record?

Post by probe1 »

I don't know how to set focus w/o using code (there is no setFocusHere action, as you found out).


just take the last five statements - change the name in getByName statement - to set the focus to YOUR control.
Cheers
Winfried

DateTime2 extension: insert date, time or timestamp, formatted to your needs
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How Do I Create a Form Button to Add a New Record?

Post by Villeroy »

If I remember correctly, each form control has a peer (a sub-window in the component window) with interface c.s.s.awt.XWindow and method setFocus().
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
jdanniel
Posts: 67
Joined: Tue Mar 04, 2008 8:25 pm

Re: How Do I Create a Form Button to Add a New Record?

Post by jdanniel »

It's not a real big deal...thanks for helping out. I was just curious about it.
crystalclear
Posts: 1
Joined: Sun Jul 19, 2009 2:32 pm

Re: How Do I Create a Form Button to Add a New Record?

Post by crystalclear »

If you create a button to add new record ,set the tab order of the control you wish to have focus to be after the button.
OOo 2.4.X on Ubuntu 8.x + XP
Post Reply