Changing Focus from Subform to Main Form

K

Kakatal

I am trying to use the same subform - subfrm1 on 2 separate main forms -
Form1 & Form2.

I have set the following Event Procedure on subfrm1 last field's On Lost
Focus property: Forms!Form1.Form!Control.SetFocus

Works fine - focus returns to Form1 control.

Of course when I add this subform to Form2, I get an error message. I was
thinking I could use an If Then Else statement to check what Main form was
open & then set the focus to the appropriate control. Not having much luck
with my VBA though. Cannot seem to be able to reference the current open
main form correctly.

Any help on how to make this work would be greatly appreciated..thanks.
 
6

'69 Camaro

Hi, Kakatal.
Of course when I add this subform to Form2, I get an error message.

One doesn't need to reference the form's name. Me.Parent will reference the
main form, no matter which one is using this subform.

It sounds like both forms have the same control name. If the control's name
is the same on both forms, then try:

Me.Parent.Controls!ControlName.SetFocus

If these controls have different names, then you can use an IF block and
Me.Parent.Name to determine the main form's name. If you are still having
trouble with the code, then please post back.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
K

Kakatal

Thanks for clearing that up for me. Works like a charm.

'69 Camaro said:
Hi, Kakatal.
Of course when I add this subform to Form2, I get an error message.

One doesn't need to reference the form's name. Me.Parent will reference the
main form, no matter which one is using this subform.

It sounds like both forms have the same control name. If the control's name
is the same on both forms, then try:

Me.Parent.Controls!ControlName.SetFocus

If these controls have different names, then you can use an IF block and
Me.Parent.Name to determine the main form's name. If you are still having
trouble with the code, then please post back.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
I am trying to use the same subform - subfrm1 on 2 separate main forms -
Form1 & Form2.
[quoted text clipped - 12 lines]
Any help on how to make this work would be greatly appreciated..thanks.
 
6

'69 Camaro

You're welcome. Glad it helped.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.


Kakatal said:
Thanks for clearing that up for me. Works like a charm.

'69 Camaro said:
Hi, Kakatal.
Of course when I add this subform to Form2, I get an error message.

One doesn't need to reference the form's name. Me.Parent will reference
the
main form, no matter which one is using this subform.

It sounds like both forms have the same control name. If the control's
name
is the same on both forms, then try:

Me.Parent.Controls!ControlName.SetFocus

If these controls have different names, then you can use an IF block and
Me.Parent.Name to determine the main form's name. If you are still having
trouble with the code, then please post back.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
I am trying to use the same subform - subfrm1 on 2 separate main forms -
Form1 & Form2.
[quoted text clipped - 12 lines]
Any help on how to make this work would be greatly appreciated..thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top