Combo Box - Limit to List

M

Martin

Hello,

I have a combo box that has a list derived from a query. I want the user to
only select data in the combo box and I have set the limit to list property
to yes but users can still type in anything they want. The error message
does display stating that it doesn't match the value in the list but I want
to prevent the user from typing in anything at all other than those in the
list.

Can anyone help?

I don't want to use a list box.

Martin
 
A

akphidelt

Can I ask why?

Cause regardless if you limit to the list they can't leave that combobox
until there is something that is in the list.
 
K

Klatuu

Use the NotInList event for your combo:

Private Sub MyCombo_NotInList(NewData As String, Response As Integer)

MsgBox "You Must Select From the List"
Response = acDataErrContinue
Me.MyCombo.Undo

End Sub
 
M

Mark A. Sam

In the KeyDown event type this:

KeyCode = 0

That will prevent typing anything at all into the combobox.

God Bless,

Mark A. Sam
 
M

Mark A. Sam

I find that prohibiting typing in comboboxes makes a cleaner application
where there are only a few choices to be made. When the user clicks on the
combo, the list drops and he makes the choice.
 
R

Ron2006

I find that prohibiting typing in comboboxes makes a cleaner application
where there are only a few choices to be made. When the user clicks on the
combo, the list drops and he makes the choice.








- Show quoted text -

However, stopping the ability to type also stops the auto complete
functionality.

Ron
 
M

Martin

Thank you all for your responses, most helpful. In particular, thank you
Mark A. Sam, just what was needed.

Martin
 
D

Dirk Goldgar

Mark A. Sam said:
In the KeyDown event type this:

KeyCode = 0

That will prevent typing anything at all into the combobox.


It will also prevent the user from tabbing out of the combo box. It would
probably be better to exclude the Tab and Enter keys from that blanket
prohibiton on typing.
 
M

Martin

Dirk,

Sorry, I am not that advanced. Can you expand on that. I have just tested
the Keycode method and it does what I need expect as you say does not allow
the tab button to work.

Martin
 
M

Mark A. Sam

Correct, but for my purpose it doesn't matter, becuase the mouse is used to
select.
 
M

Mark A. Sam

Dick,

That's true, but can be accounted for.

If KeyCode <> 9 Then 'Tab key pressed
KeyCode = 0
End If

God Bless,

Mark
 
D

Dirk Goldgar

Mark A. Sam said:
Dick,
Dirk

That's true, but can be accounted for.

If KeyCode <> 9 Then 'Tab key pressed
KeyCode = 0
End If

Exactly. Though you probably want to allow 13 as well:

Select Case KeyCode
Case 9, 13
' Allow these
Case Else
' Ignore all other keys.
KeyCode = 0
End Select
 
B

Bob Quintal

Correct, but for my purpose it doesn't matter, becuase the mouse
is used to select.


You are the only user of the database?
Or are you one of those arrogant coders who insist that their way is
correct and everybody who has a different way is an id10t?

Use the combobox's On Key Press event to capture all keystrokes and
discard them, possibly except for the enter key and or escape key.

Q
 
M

Mark A. Sam

Bob,

You misunderstood me. I was just answering Ron. I don't think there are
many times to use this method, but if there are only a few, static choices,
it can work well. If circumstances changed and the list increased then the
method could easily be changed. Any methodolgy would depend on the user and
the usage.

God Bless,

Mark
 
B

Bob Quintal

Bob,

You misunderstood me. I was just answering Ron. I don't think
there are many times to use this method, but if there are only a
few, static choices, it can work well. If circumstances changed
and the list increased then the method could easily be changed.
Any methodolgy would depend on the user and the usage.

God Bless,

Mark
My apologies. Ron's the one that needs to answer the questions (to
himself if not to me) before he alienates a lot of users.
Bob Quintal said:
You are the only user of the database?
Or are you one of those arrogant coders who insist that their way
is correct and everybody who has a different way is an id10t?

Use the combobox's On Key Press event to capture all keystrokes
and discard them, possibly except for the enter key and or
escape key.

Q
 
R

Ron2006

My apologies. Ron's the one that needs to answer the questions (to
himself if not to me) before he alienates a lot of users.

Ron?

I just said it disables the autocomplete.

Ron
 
B

Bob Quintal

(e-mail address removed)
m:
Ron?

I just said it disables the autocomplete.

Ron

Sorry Ron, I mistook you for the Original Poster. The OP is the one
that needs to abnswer the question. Quoting seems to have mangled
who said what.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

NotInList 1
NotInList 3
List box selection into combo box 2
Limit combo box to list or Null 1
Limit to List 1
Combo Box - Not In List 1
Droplist/Combo box 4
Combo Box Limit to List Problem 3

Top