Determine which subform has focus

I have two subforms on a form.  I have a function that runs, but I want just a couple of lines to not be ran if one subform has the focus rather than the other one.  I want to insert an IF statement, but what syntax would I use to determine which subform has focus:

Example:  If subform1 has focus then...
sf_garrisonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tomedickCommented:
I don't believe there is a way to determine whether a subform has the focus, and generally it won't be the subform that has the focus, but rather one of the controls on it.  Here is a quick and easy way to accomplish what you want though:
On The Main Form create an unbound checkbox and set it's visible property to false, set it's name to whatever you want.  Let's say you call it 'Check1'
In the main form create an Event Procedure in each subform control's 'OnEnter' property that will turn on or off the checkbox depending on which form it is.

Private Sub Subform1_Enter()
   Me.Check1 = True
End Sub

Private Sub Subform2_Enter()
   Me.Check1 = False
End Sub

This will set the checkbox to true whenever you enter subform1 and turn it off whenever you enter subform2.  You can then test the state of the checkbox in your code.

If Me.Check1 = True Then ......
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sf_garrisonAuthor Commented:
Thanks for the quick reply on a Saturday night !
0
tomedickCommented:
Glad to help
0
mbizupCommented:
The ActiveControl property tells you exactly which control has the focus.  You can also use that to determine if the focus is on (or within) a particular subform:

If Forms!MyformName.ActiveControl.Name = "SubForm1"  then
   ....
end if

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.