Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Accessing a SubForm from a Form


Message #1 by "Mark Irvine" <markpirvine@b...> on Thu, 16 Aug 2001 08:49:38 +0100
Hi,



I was wondering if it is possible to access a subform element for the main

form.  What I am trying to achieve is to have focus set to the first element

of the subform once all entries have been completed in the form.  At the

moment when focus is directed at the subform, the last element to be

active - which is not necessarily the first element - takes focus.  Anyone

any suggestions.



Mark





Message #2 by "Sanna Korpela" <sanna.m.korpela@l...> on Thu, 16 Aug 2001 10:35:27
Hi Mark!

I suggest you set the tabindex of the elements of your subform. That can 

be done in the property-window of a element. It means that when using 

enter, tabbutton or arrows in moving, the selection moves in that order. 



Tabindexes start from 0 in the main form and also from 0 in subform. The 

whole subform is one element in the main form and has it's tabindex also.



Hope this will help you,

Sanna



ps.When you find out how to move selection from subform to element after 

that (in the main form), let me know.



Message #3 by "Pardee, Roy E" <roy.e.pardee@l...> on Thu, 16 Aug 2001 08:13:47 -0700
I don't know of any neat way of getting Access to keep track of which

subform control was last active & resetting the focus there, but you could

program it yourself in VBA if you're motivated enough. 8^)



Most Access controls have a method called .SetFocus, which you can use in

VBA to direct the focus to that control.  To refer to subform controls from

code living in the main form, you go through the .Form property of the

subform control.  So to set the focus on a text box called txtMyField, which

lives on a form contained in a subform control called sbfMySubForm, you

could say:



	Me.sbfMySubForm.Form.Controls("txtMyField").SetFocus



To keep track of which control last had the focus, you could (for instance)

put VBA code behind the subform that updated a module-level variable each

time a control got the focus.  Then in the OnEnter event of the subform

control you could call a subroutine in the subform that set the focus to the

appropriate control.  It'd be a lot of trouble, but that's the best way I

can think to do it--maybe someone else can think of an easier way.



HTH,



-Roy



-----Original Message-----

From: Mark Irvine [mailto:markpirvine@b...]

Sent: Thursday, August 16, 2001 12:50 AM

To: Access

Subject: [access] Accessing a SubForm from a Form





Hi,



I was wondering if it is possible to access a subform element for the main

form.  What I am trying to achieve is to have focus set to the first element

of the subform once all entries have been completed in the form.  At the

moment when focus is directed at the subform, the last element to be

active - which is not necessarily the first element - takes focus.  Anyone

any suggestions.



Mark

Message #4 by "Mark Irvine" <mark@m...> on Thu, 16 Aug 2001 22:27:11 +0100
Roy,



Many thanks for your response.  The

'Me.sbfMySubForm.Form.Controls("txtMyField").SetFocus' was what I was

looking for!



Mark

"Pardee, Roy E" <roy.e.pardee@l...> wrote in message

news:94180@a...

>

> I don't know of any neat way of getting Access to keep track of which

> subform control was last active & resetting the focus there, but you could

> program it yourself in VBA if you're motivated enough. 8^)

>

> Most Access controls have a method called .SetFocus, which you can use in

> VBA to direct the focus to that control.  To refer to subform controls

from

> code living in the main form, you go through the .Form property of the

> subform control.  So to set the focus on a text box called txtMyField,

which

> lives on a form contained in a subform control called sbfMySubForm, you

> could say:

>

> Me.sbfMySubForm.Form.Controls("txtMyField").SetFocus

>

> To keep track of which control last had the focus, you could (for

instance)

> put VBA code behind the subform that updated a module-level variable each

> time a control got the focus.  Then in the OnEnter event of the subform

> control you could call a subroutine in the subform that set the focus to

the

> appropriate control.  It'd be a lot of trouble, but that's the best way I

> can think to do it--maybe someone else can think of an easier way.

>

> HTH,

>

> -Roy

>

> -----Original Message-----

> From: Mark Irvine [mailto:markpirvine@b...]

> Sent: Thursday, August 16, 2001 12:50 AM

> To: Access

> Subject: [access] Accessing a SubForm from a Form

>

>

> Hi,

>

> I was wondering if it is possible to access a subform element for the main

> form.  What I am trying to achieve is to have focus set to the first

element

> of the subform once all entries have been completed in the form.  At the

> moment when focus is directed at the subform, the last element to be

> active - which is not necessarily the first element - takes focus.  Anyone

> any suggestions.

>

> Mark

>

>





Message #5 by John Fejsa <John.Fejsa@h...> on Fri, 17 Aug 2001 08:11:02 +1000
Example:



Forms!MyForm!MySubform.Form!MyField.SetFocus



This will set focus to a field called MyField (!) that's located on the 

subform(.Form) called MySubform (!).  The subform is located on the main 

form (Forms) called MyForm (!).  Hope that helps.



JohnF



>>> markpirvine@b... 16/08/2001 17:49:38 >>>

Hi,



I was wondering if it is possible to access a subform element for the main

form.  What I am trying to achieve is to have focus set to the first 

element

of the subform once all entries have been completed in the form.  At the

moment when focus is directed at the subform, the last element to be

active - which is not necessarily the first element - takes focus.  Anyone

any suggestions.



Mark




  Return to Index