By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,491 Members | 1,868 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,491 IT Pros & Developers. It's quick & easy.

HasFocus

P: 48
I have the following :

Public Sub ObjectFormatting(ByRef objTarget As Variant)
SetObjectBorderWidth objTarget, IIf(HasFocus(objTarget), 2, 0)
End Sub

and

Function HasFocus(objControl As Control) As Boolean
If Screen.ActiveControl Is objControl Then
HasFocus = True
Else
HasFocus = False
End If
End Function

Both the Sub as the Function are in another module. The object provided to HasFocus resides on a SubForm

I always get an error 2474 (control must be in active window) on the Screen.ActiveControl

What am I overlooking ?

Thanks
Jan 25 '08 #1
Share this Question
Share on Google+
3 Replies


puppydogbuddy
Expert 100+
P: 1,923
I have the following :

Public Sub ObjectFormatting(ByRef objTarget As Variant)
SetObjectBorderWidth objTarget, IIf(HasFocus(objTarget), 2, 0)
End Sub

and

Function HasFocus(objControl As Control) As Boolean
If Screen.ActiveControl Is objControl Then
HasFocus = True
Else
HasFocus = False
End If
End Function

Both the Sub as the Function are in another module. The object provided to HasFocus resides on a SubForm

I always get an error 2474 (control must be in active window) on the Screen.ActiveControl

What am I overlooking ?

Thanks

Screen.ActiveForm and Screen.ActiveControl work as long as the form or control that has focus is the Main form. It does not work if the control is on the subform. The following link has a function (Set_Screen_ActiveSubformControl()) that you can use with a form or subform. http://support.microsoft.com/kb/210210
Jan 27 '08 #2

P: 48
Screen.ActiveForm and Screen.ActiveControl work as long as the form or control that has focus is the Main form. It does not work if the control is on the subform. The following link has a function (Set_Screen_ActiveSubformControl()) that you can use with a form or subform. http://support.microsoft.com/kb/210210
Hi

Thank you very much, seems this is going to be the solution to my problem. Nevertheless I'm somehow confused how to use it. I've created two functions, which are intented to return a True when the active control is identical to the one provided as parameter. But seems not to work. Any idea what might be wrong ?

Function ReturnScreenActiveControl(ByRef objTarget As Variant)
If Set_Screen_ActiveSubformControl() = False Then
ReturnScreenActiveControl = False
Else
ReturnScreenActiveControl = IIf(Screen.ActiveControl = objTarget, True, False)
End If
End Function

Function ReturnScreenActiveControl2(ByRef txbTarget As Access.TextBox)
If Set_Screen_ActiveSubformControl() = False Then
ReturnScreenActiveControl2 = False
Else
ReturnScreenActiveControl2 = IIf(Screen.ActiveControl = txbTarget, True, False)
End If
End Function

Thanks
Jan 31 '08 #3

jaxjagfan
Expert 100+
P: 254
Hi

Thank you very much, seems this is going to be the solution to my problem. Nevertheless I'm somehow confused how to use it. I've created two functions, which are intented to return a True when the active control is identical to the one provided as parameter. But seems not to work. Any idea what might be wrong ?

Function ReturnScreenActiveControl(ByRef objTarget As Variant)
If Set_Screen_ActiveSubformControl() = False Then
ReturnScreenActiveControl = False
Else
ReturnScreenActiveControl = IIf(Screen.ActiveControl = objTarget, True, False)
End If
End Function

Function ReturnScreenActiveControl2(ByRef txbTarget As Access.TextBox)
If Set_Screen_ActiveSubformControl() = False Then
ReturnScreenActiveControl2 = False
Else
ReturnScreenActiveControl2 = IIf(Screen.ActiveControl = txbTarget, True, False)
End If
End Function

Thanks
What are you trying to do here? What is the overall process? Are you trying to exit a function or perform an action when a control has focus. I don't know if this applies but I check the value of controls before I allow a process to continue.

If isnull(Me.txt1) then
Msgbox "You must enter a value!"
me.txt1.SetFocus
exit sub
Else
DoMyThing
End if
Jan 31 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.