| View previous topic :: View next topic |
| Author |
Message |
timinak General User

Joined: 03 Mar 2011 Posts: 28 Location: Palmer Alaska
|
Posted: Sun May 13, 2012 5:33 pm Post subject: How to default focus on new form record to first field |
|
|
Using OO 3.2 on Ubuntu 10.04. Have a form designed.
Automatic Control Focus is set to on. Thus, when the form
is first opened, the focus is on the first field. Good.
When a record is edited or created and the next button is clicked,
Focus is on the same field as was in focus in the previous record.
Bad
How can I insure that focus is always on the first field for a new record?
It is driving my wife crazy. Help me save my marriage. No, just kidding, but
help me to put her in a better mood.
thanks
tim _________________ Programmer 24 years. Linux, Mac
command-line. New to OO |
|
| Back to top |
|
 |
dacm Super User


Joined: 07 Jan 2010 Posts: 734
|
Posted: Mon May 14, 2012 12:46 pm Post subject: Re: How to default focus on new form record to first field |
|
|
tim,
That's beyond the function of 'Automatic Control Focus' (which only functions upon initially opening the Form). But a Macro could do the trick:
| Code: | Sub SetFocus 'Form > Events > After Record Change
' replace ("names") below with the names of your Form(s) and focused Control as necessary
oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")'.getByName("SubForm")
cControl = oForm.getByName("Table Control 1") 'replace with the name of the Control receiving focus
oControlView = ThisComponent.CurrentController.getControl(cControl) 'workaround...API should expose the View from oControl
oControlView.SetFocus
' wait 100 'may be necessary before next step with slower CPU's
' oControlView.setCurrentColumnPosition(0) 'additional step to select a specific column within a Table Control (grid)
End Sub |
_________________ Soli Deo gloria
Tutorial: avoiding data loss with Base + Migrating 'Embedded databases'
Last edited by dacm on Mon May 14, 2012 8:27 pm; edited 3 times in total |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Mon May 14, 2012 1:45 pm Post subject: |
|
|
Hello
When you play with the tab-order in the form can you get what you want?
Romke _________________ OOo 3.4.5 on openSUSE 12.1
Use this forum : http://user.services.openoffice.org/en/forum |
|
| Back to top |
|
 |
timinak General User

Joined: 03 Mar 2011 Posts: 28 Location: Palmer Alaska
|
Posted: Mon May 14, 2012 2:22 pm Post subject: |
|
|
Hello dacm:
I'm not surprised it would take a macro. I did take a look at macros
available and couldn't find what I wanted. Thanks very much. I will give that a try.
Oh, and RPG, I set the TAB order to coincide with the physical order of the fields,
going from left to right and 'uppermost' line to lowermost.
Could you elaborate on your comment?
Othewise, I looking forward to practicing on my first macro.
cheers
tim _________________ Programmer 24 years. Linux, Mac
command-line. New to OO |
|
| Back to top |
|
 |
dacm Super User


Joined: 07 Jan 2010 Posts: 734
|
Posted: Mon May 14, 2012 2:39 pm Post subject: |
|
|
| RPG wrote: | | When you play with the tab-order in the form can you get what you want? |
The tab-order determines which Control receives the focus upon opening a Form with 'Automatic Control Focus' selected/enabled. Otherwise, if 'Automatic Control Focus' is not selected, no Control receives focus and the user must select a Control manually -- so 'Automatic Control Focus' saves a mouse-click.
Once interaction with the Form commences, 'Automatic Control Focus' doesn't seem to apply. Tab-order works as advertised when tabbing, but doesn't drive the focus back to the first Control in tab-order when changing records (navigating between records). The focus simply remains on the last selected Control.
So I think we're left with a macro-driven solution...  _________________ Soli Deo gloria
Tutorial: avoiding data loss with Base + Migrating 'Embedded databases' |
|
| Back to top |
|
 |
timinak General User

Joined: 03 Mar 2011 Posts: 28 Location: Palmer Alaska
|
Posted: Mon May 14, 2012 2:47 pm Post subject: |
|
|
Indeed, a macro-based solution it is. Thanks again _________________ Programmer 24 years. Linux, Mac
command-line. New to OO |
|
| Back to top |
|
 |
dacm Super User


Joined: 07 Jan 2010 Posts: 734
|
Posted: Mon May 14, 2012 3:01 pm Post subject: |
|
|
| timinak wrote: | ...I looking forward to practicing on my first macro.  |
Macros are often necessary to tweak Form usability for end-users. But in the early stages of learning Base, don't assume you need a macro until searching or posing the question in these forums -- just as you've done. You'll be amazed what Base can do without macros. Besides, folks won't always write macros for you and over-reliance on macros can undermine proper database and/or Form design which can cause bigger problems down the road. _________________ Soli Deo gloria
Tutorial: avoiding data loss with Base + Migrating 'Embedded databases' |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Mon May 14, 2012 3:38 pm Post subject: |
|
|
Hello
I did not read careful enough the question. I was thinking the problem was only for the first field and I did not see also a new record.
I think the solution of DACM is right. When you want only add data then you can go to a new record. Set the form to: add data only.
Romke _________________ OOo 3.4.5 on openSUSE 12.1
Use this forum : http://user.services.openoffice.org/en/forum |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Tue May 15, 2012 2:15 am Post subject: |
|
|
Hello
After better reading I do understand better the problem. I'm not sure if it works always and also if you can use it.
| Code: | sub Activatefirst_AfterRecord_change(oEvent as object)
Thiscomponent.currentcontroller.getFormController(oEvent.source).activateFirst
end sub |
Romke _________________ OOo 3.4.5 on openSUSE 12.1
Use this forum : http://user.services.openoffice.org/en/forum |
|
| Back to top |
|
 |
RPG Super User

Joined: 24 Apr 2008 Posts: 2696 Location: Apeldoorn, Netherland
|
Posted: Tue May 15, 2012 2:24 am Post subject: |
|
|
Hello
This can work when you want set the focus on an other control then the first one.
| Code: | sub Activatefirst_AfterRecord_change(oEvent as object)
dim oFormController
oFormController=Thiscomponent.currentcontroller.getFormController(oEvent.source)
oFormController.controls(3).setfocus
end sub
|
_________________ OOo 3.4.5 on openSUSE 12.1
Use this forum : http://user.services.openoffice.org/en/forum |
|
| Back to top |
|
 |
|