?
Solved

Determine which subform has focus

Posted on 2007-10-20
4
Medium Priority
?
644 Views
Last Modified: 2008-01-09
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...
0
Comment
Question by:sf_garrison
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
tomedick earned 2000 total points
ID: 20116454
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
 

Author Comment

by:sf_garrison
ID: 20116460
Thanks for the quick reply on a Saturday night !
0
 
LVL 3

Expert Comment

by:tomedick
ID: 20116493
Glad to help
0
 
LVL 61

Expert Comment

by:mbizup
ID: 20116621
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question