Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Focus on combobox

Does anyone know how to test, in VBA, if a combobox on a sheet has the focus or not?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Focus on combobox

If from the control toolbox toolbar, have you tried using the GotFocus and
Lostfocus events?

--
Regards,
Tom Ogilvy


atkscott wrote in message
m...
Does anyone know how to test, in VBA, if a combobox on a sheet has the

focus or not?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Focus on combobox

Tom,
The root of my problem is that when a user clicks on the combobox, focus
is transfered and the gotfocus event is triggered. No problem there. If
then the user clicks on the combobox and selects the same list choice,
NO event is triggered. The control already has focus, focus is
mantained, value hasn't changed so there's no change event and for some
reason no click event is triggered. A code condition that CAN follow
after this condition attemts to unprotect this locked sheet.

The unprotect code fails.

Sheets("Main").Unprotect (Sheets("Data").Range("G3"))

I need to detect this condition and if it exists, temporarily move focus
off it and after the unprotect code block runs, return it.


Thanks,
Scott

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Focus on combobox

Set a flag in the _GotFocus event, reset it in the _LostFocus event.
Then, to determine whether the control has focus, check the value of
the flag.

As an aside, just for interest, this code determines that the user
changed the value, even if they select the same list choice (also:
consider when the user changes the combo using the keyboard):

Option Explicit

Private Enum owComboStateEnum
owComboStateNormal = 1
owComboStateIsDropping = 2
owComboStateDropped = 3
End Enum

Private m_lngComboState As owComboStateEnum

Private Sub ComboBox1_DropButtonClick()
ComboState = owComboStateIsDropping
End Sub

Private Sub ComboBox1_LostFocus()
ComboState = owComboStateNormal
End Sub

Private Sub ComboBox1_MouseUp(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
Select Case ComboState
Case owComboStateIsDropping
ComboState = owComboStateDropped
Case owComboStateDropped
Debug.Print "Success: ComboBox1 will change from '" & _
ComboBox1.Value & "' to unknown."
ComboState = owComboStateNormal
End Select
End Sub

Private Property Let ComboState(ByVal NewValue As owComboStateEnum)
m_lngComboState = NewValue
End Property

Private Property Get ComboState() As owComboStateEnum
ComboState = m_lngComboState
End Property


Scott Harmala wrote in message ...
Tom,
The root of my problem is that when a user clicks on the combobox, focus
is transfered and the gotfocus event is triggered. No problem there. If
then the user clicks on the combobox and selects the same list choice,
NO event is triggered. The control already has focus, focus is
mantained, value hasn't changed so there's no change event and for some
reason no click event is triggered. A code condition that CAN follow
after this condition attemts to unprotect this locked sheet.

The unprotect code fails.

Sheets("Main").Unprotect (Sheets("Data").Range("G3"))

I need to detect this condition and if it exists, temporarily move focus
off it and after the unprotect code block runs, return it.


Thanks,
Scott

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Focus on combobox

Funning things happen when you get so buried in your code...Thanks
onedaywhen for pointing out the obvious :)

(onedaywhen) wrote in message . com...
Set a flag in the _GotFocus event, reset it in the _LostFocus event.
Then, to determine whether the control has focus, check the value of
the flag.

As an aside, just for interest, this code determines that the user
changed the value, even if they select the same list choice (also:
consider when the user changes the combo using the keyboard):

Option Explicit

Private Enum owComboStateEnum
owComboStateNormal = 1
owComboStateIsDropping = 2
owComboStateDropped = 3
End Enum

Private m_lngComboState As owComboStateEnum

Private Sub ComboBox1_DropButtonClick()
ComboState = owComboStateIsDropping
End Sub

Private Sub ComboBox1_LostFocus()
ComboState = owComboStateNormal
End Sub

Private Sub ComboBox1_MouseUp(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
Select Case ComboState
Case owComboStateIsDropping
ComboState = owComboStateDropped
Case owComboStateDropped
Debug.Print "Success: ComboBox1 will change from '" & _
ComboBox1.Value & "' to unknown."
ComboState = owComboStateNormal
End Select
End Sub

Private Property Let ComboState(ByVal NewValue As owComboStateEnum)
m_lngComboState = NewValue
End Property

Private Property Get ComboState() As owComboStateEnum
ComboState = m_lngComboState
End Property


Scott Harmala wrote in message ...
Tom,
The root of my problem is that when a user clicks on the combobox, focus
is transfered and the gotfocus event is triggered. No problem there. If
then the user clicks on the combobox and selects the same list choice,
NO event is triggered. The control already has focus, focus is
mantained, value hasn't changed so there's no change event and for some
reason no click event is triggered. A code condition that CAN follow
after this condition attemts to unprotect this locked sheet.

The unprotect code fails.

Sheets("Main").Unprotect (Sheets("Data").Range("G3"))

I need to detect this condition and if it exists, temporarily move focus
off it and after the unprotect code block runs, return it.


Thanks,
Scott

*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
fill combobox depending on selection from another combobox Adam Francis Excel Discussion (Misc queries) 2 July 24th 08 07:39 PM
focus Capp Excel Discussion (Misc queries) 2 November 18th 05 07:25 PM
set focus tkaplan Excel Discussion (Misc queries) 3 September 27th 05 07:41 PM
Focus David Unger Excel Worksheet Functions 20 March 21st 05 06:43 PM
set focus RickK Excel Programming 1 October 10th 03 12:27 PM


All times are GMT +1. The time now is 06:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"