Combo Box

Stemdriller

Registered User.
Local time
Today, 19:48
Joined
May 29, 2008
Messages
187
Hi All

On a Combo how can I stop users entering there own values??

I've done it before but simply cannot remember how??

Thanks
 
Look in the Data tab you will see a property that should ring a bell ;)
 
I'm looking but no bells are ringing.

Just a combo box, not the whole form
 
Limit To List?

Ah, hang on. Are talking about stopping them from typing completely?
 
Replacing ComboBoxName with the actual name of your Combobox:
Code:
Private Sub ComboBoxName_KeyDown(KeyCode As Integer, Shift As Integer)
 Select Case KeyCode
  Case vbKeyReturn, vbKeyTab, vbKeyUp, vbKeyDown
   KeyCode = KeyCode  'Accept these keys
  Case Else
   KeyCode = 0 ‘Block all other keys
 End Select
End Sub
Linq ;0)>
 
... and if you want to allow users copy text (but not paste using Ctrl + V), allow them highlight text using the arrow keys etc, you can use this:
Code:
    If Shift = 2 And KeyCode = 86 Then
        KeyCode = 0     ' disable Cut shortcut
    ElseIf Shift <> 2 Then
        Select Case KeyCode
            Case vbKeyReturn, vbKeyTab, vbKeyUp, vbKeyDown, vbKeyLeft, vbKeyRight, vbKeyHome, vbKeyEnd
                KeyCode = KeyCode  'Accept these keys
            Case Else
                KeyCode = 0 'Block all other keys
        End Select
    End If
You will need to create a custom Shortcut menu bar for your control's right click if you wish to disable pasting via right-clicking.
 

Users who are viewing this thread

Back
Top Bottom