combobox prevent typing, force to select from list

Rx_

Nothing In Moderation
Local time
Today, 07:45
Joined
Oct 22, 2009
Messages
2,803
Searched to find the best method to prevent users from typing in a Limit to List Combo Box. It allows Tab, Esc, upkey, downkey
Before posting this into Code Repository - does anyone else have suggestions, alternatives, or enhancements to contribute?

Combobox - provides a list to select where users must choose from list.
Problem, even when Limit To List is Yes- users can get in and start typing.
One common solution is to present users with a message box "please don't press that button again".

This solution forces uses to select from the list, or Esc, or Tab.

Settings: List = yes, Allow Value list Edits = no
When the control gets focus the list auto-expands.
Disadvantage, the user can not type into and search for an existing entry - they must choose a value (or select a new value).
The up and down arrow key allows navigation if the list is long.
The Tab or Esc allows to move to the next object or un-select.
Code:
Private Sub Wells_Pad_Group_KeyPress(KeyAscii As Integer)
        '  in this combobox Got focus - use this to automatically expand the list:  Me.Wells_Pad_Group.Dropdown ' force the Autoexpand
10        Select Case KeyAscii
            'do allow Esc, Tab
            Case Asc(3), Asc(9), Asc(38), Asc(40)   ' , Asc("?"), Asc("@"), Asc("-"), Asc("*"), Asc("+"), Asc("&"), Asc("#"), Asc("!"), Asc("'"), Asc("/")
              'do nothing except allow a Tab or Esc (or arrow keys)
20          Case Else
30              KeyAscii = 0
              'list to allow Keystroke to be processed   ' http://msdn.microsoft.com/en-us/library/aa243025(v=vs.60).aspx
40          End Select
End Sub

It is not a solution for everyone or every situation.
Be sure in File Options, Current Database Name AutoCorrect Options
Turn off the Track name AutoCorrect info. It might sometimes cause a combo box list to snap shut.
 

Attachments

  • cmbBoxNotype.png
    cmbBoxNotype.png
    9.7 KB · Views: 227

Users who are viewing this thread

Back
Top Bottom