• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 319
  • Last Modified:

Detect which subform is active

In Access 2003, I have a form Main that is a holder for several subforms, including Action and Task.  (They aren't linked to the MAIN form, it's just a shell/holder.  I have these subforms on fixed positions on the Main form instead of floating for various reasons that are *currently* more important that the feature I'm asking about here).

I would like to be able to set a global string variable TaskOrAction to either "Task" or "Action" when that respective subform is activated.

I need to find an event that I can use to detect that the subform is activated, or, more specifically, if ANY control on that subform is used, so I can set the value of TaskOrAction (which I use later to inform a query of whether to look for a key value in ...Task or Action).

I tried a few things that didn't work:
1)  According to MS, "Activate" does not work for subforms,

2)  According to this, http://www.access-programmers.co.uk/forums/showthread.php?t=191507
GotFocus does not work unless you use the record selector (though I did not see that happen either, when I tried GotFocus

3)  Enter only works for specific controls, and I need to set the variable if any control on the subform is used, or if the subform record selector is keyed.

I built a little test bed, attached.

Any suggestions on this would be appreciated.

Thanks!

Test.mdb
0
codequest
Asked:
codequest
  • 3
2 Solutions
 
Dale FyeCommented:
Have you looked at the subform controls "Enter" and "Exit" events.  You could declare a variable in the Main form and use the subforms Enter and Exit events to set the value of that variable.

Depending on where you want this code to fire, say in a public module, you could use something like:

?screen.ActiveForm.activecontrol.name

If the focus is on one of the controls on the main form, this would print out "Main", but if the focus is one of the textboxes in a subform, it would give the name of the subform.
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Try this:

mx
Test-MX01.mdb
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
A slightly better version ...
Test-MX02.mdb
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
"1)  According to MS, "Activate" does not work for subforms, "
That is correct.

We are basically using

Screen.ActiveForm.ActiveControl.Parent.Name

keeping in mind that a subform IS a Control ... a container for an actual Form - to be used as a subform.

mx
0
 
codequestAuthor Commented:
Works slick.  Thanks!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now