Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to disable the "ESC feature" of a ComboBox?

I've a UserForm with a ComboBox with e.g. 10 items.

Private Sub UserForm_Initialize()
Dim Counter As Long

For Counter = 1 To 10
ComboBox1.AddItem "MyItem " & Counter
Next

ComboBox1.ListIndex = 5
End Sub

Choose another item in the ComboBox. Now, if you press 'Esc' the
before selected item gets selected (and there is also no KeyPress
event if you press 'Esc' the first time).
How can I disable this feature? I don't want that 'Esc' selects the
before selected item. I like e.g. 'Esc' to close the UserForm.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default How to disable the "ESC feature" of a ComboBox?

Hi Stefan,

This should help, although it still won't work if Escape is pressed whilst
the Combobox list is still dropped down. If you Choose a list item first, or
are using the cursors to navigate up and down the list then this should
prevent the list resetting to the last item.

Try using this code in your form:

'These are variables for the form in general
Dim cboVal As Long
Dim boolEsc As Boolean
Option Explicit

Private Sub ComboBox1_Change()
If boolEsc = True Then
boolEsc = False
ComboBox1.ListIndex = cboVal
Else
cboVal = ComboBox1.ListIndex
boolEsc = False
End If
End Sub

Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 27 Then
boolEsc = True
End If
End Sub

Private Sub UserForm_Initialize()
Dim Counter As Long
boolEsc = False
For Counter = 1 To 10
ComboBox1.AddItem "MyItem " & Counter
Next
ComboBox1.ListIndex = 5
End Sub



Sean.



"Stefan Mueller" wrote:

I've a UserForm with a ComboBox with e.g. 10 items.

Private Sub UserForm_Initialize()
Dim Counter As Long

For Counter = 1 To 10
ComboBox1.AddItem "MyItem " & Counter
Next

ComboBox1.ListIndex = 5
End Sub

Choose another item in the ComboBox. Now, if you press 'Esc' the
before selected item gets selected (and there is also no KeyPress
event if you press 'Esc' the first time).
How can I disable this feature? I don't want that 'Esc' selects the
before selected item. I like e.g. 'Esc' to close the UserForm.


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
Disable autoformat of "true" and "false" text drs207 Excel Discussion (Misc queries) 6 April 14th 23 05:33 PM
Disable the "Disabled Items" feature Luca Brasi Setting up and Configuration of Excel 0 April 29th 10 10:25 AM
how can I disable "cutting cells" and "drag and drop "in excel ? mwoody Excel Worksheet Functions 4 August 25th 08 03:53 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Disable "Save" &/or "Close" universal[_4_] Excel Programming 3 October 25th 03 12:38 PM


All times are GMT +1. The time now is 06:42 AM.

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

About Us

"It's about Microsoft Excel"