PC Review


Reply
Thread Tools Rate Thread

How to disable the "ESC feature" of a ComboBox?

 
 
Stefan Mueller
Guest
Posts: n/a
 
      23rd Jul 2007
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 With Quote
 
 
 
 
=?Utf-8?B?U2VhbkMgVUs=?=
Guest
Posts: n/a
 
      24th Jul 2007
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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Less used toolbar buttons are disappearing... how to disable this "feature" Erik Microsoft Word New Users 3 11th Jul 2006 05:06 AM
How to disable auto reboot "feature" from windows update =?Utf-8?B?ZWNlbGxpcw==?= Windows XP General 5 5th Jul 2006 09:05 PM
disable the "on behalf of" feature in outlook 2000 =?Utf-8?B?QW5raXQ=?= Microsoft Outlook Discussion 5 4th Mar 2006 11:18 PM
disable "force to top" feature when opening Outlook? =?Utf-8?B?Y2hyaXNzeQ==?= Microsoft Outlook Discussion 6 21st Dec 2005 03:57 PM
Here's a macro that will globallly disable annoying "Show in Groups" feature andreas gammel Microsoft Outlook VBA Programming 0 9th Jun 2004 09:11 AM


Features
 

Advertising
 

Newsgroups
 


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