473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

HasFocus

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
3 4611
puppydogbuddy
1,923 Expert 1GB
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
wquatan
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
254 Expert 100+
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

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

Similar topics

0
by: Jim Katz | last post by:
I think I have found a bug in the behavior of the TreeCellRenderer setTextNonSelectionColor method. Instead of setting the text color for the current cell, it sets the color of the following row...
1
by: Ben Munday | last post by:
Hi all, I have a problem with a Checkbox in a JTable. When i add the Checkbox into the JTable it displays the String representation of the Checkbox, which is not what i want. So, i created a...
1
by: asd | last post by:
I need to make the cells in the 1st column look like the column header. I tried the following code but it didn't change anything: private void rendererTest() { TableColumn column =...
9
by: CW | last post by:
I wrote an HTML based chat application. The front end is built entirely on HTML + javascript. Essentially, I have a hidden frame that's refreshed frequently and any new messages are displayed in...
3
by: XSi | last post by:
very simple: is there any way I can get what field has focus in the form? I would like to trap the "backspace" only if focus is on spesific field. Thanks XSi
3
by: Philip Townsend | last post by:
I have an aspx page that contains 2 user controls, each containing a seperate textbox and button. I would like to specify that one of the buttons recieve focus when the page loads. Also, I would...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
5
by: Jordan Pittman | last post by:
how can you set a Global variable and set it to Y when a text field has focus and N when the text field does not have focus and then depending on the value preforms a task inside a function (for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.