Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine whether subform has focus

Status
Not open for further replies.

faeryfyrre

Programmer
Aug 4, 2003
198
AU
Hi,
Just though i'd share a little trick i just worked out.

It relates to determining which subform on you mainform has focus. This trick will allow a subform to determine whether it has the focus.

Scenario:
I have a mainform with two subforms. The second subform is actually dependant on the first subform and therefore whenever the first subform changes record the second subform requeries and runs it's OnCurrent event. Now i only wanted the code in the second subform's OnCurrent event to run when the second subform has the focus. The problem was determining whether the second subform had the focus.

Solution:
First, i tried testing Screen.ActiveForm.name but it always evaluated to the MAINFORM.
Second, i tried testing Screen.ActiveControl.name but that threw an error whenever a subform had the focus. Therefore Screen.ActiveControl can only be referenced when Screen.ActiveForm has the focus.

My last attempt at solving this involved testing Screen.ActiveForm.ActiveControl.name and with this i was successful.

Therefore, the OnCurrent event in my subform looks like this.

Private Sub Form_Current()
If Screen.ActiveForm.ActiveControl.name = Me.name Then
....
'the code i wanted to run
....
End If
End Sub



Hope this saves someone else the time it took me to work out.

Alec Doughty
Doughty Consulting P/L

"Life's a competition. Play hard, but play fair"
 
I'd be interested to see if anyone else has an alternative method.

Alec Doughty
Doughty Consulting P/L

"Life's a competition. Play hard, but play fair"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top