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

Creating and using forms

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

Postby jdanniel » Sat Mar 22, 2008 1:46 pm

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
jdanniel
 
Posts: 67
Joined: Tue Mar 04, 2008 8:25 pm

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

Postby Villeroy » Sat Mar 22, 2008 1:55 pm

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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 25366
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby probe1 » Sun Mar 23, 2008 12:35 am

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   Expand viewCollapse view
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
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?

Postby jdanniel » Sun Mar 23, 2008 7:01 pm

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
jdanniel
 
Posts: 67
Joined: Tue Mar 04, 2008 8:25 pm

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

Postby probe1 » Tue Mar 25, 2008 6:07 pm

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
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?

Postby Villeroy » Tue Mar 25, 2008 6:18 pm

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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 25366
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby jdanniel » Tue Mar 25, 2008 11:33 pm

It's not a real big deal...thanks for helping out. I was just curious about it.
jdanniel
 
Posts: 67
Joined: Tue Mar 04, 2008 8:25 pm

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

Postby crystalclear » Sun Jul 19, 2009 2:53 pm

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
crystalclear
 
Posts: 1
Joined: Sun Jul 19, 2009 2:32 pm


Return to Forms

Who is online

Users browsing this forum: No registered users and 3 guests