faeryfyrre
Programmer
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"
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"