Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about using combo box

Status
Not open for further replies.

deadfish

Programmer
Nov 13, 2002
50
0
0
HK
Hi,

I would like to prevent user from entering any text into the combo box. They can just select one of the items in it. I have use the "Limit to list" property to Yes. But user still can enter text in the text box, although there will be error message if the user try save the record. If the "Lock" property set to "Yes", though I can prevent user from enter text in it, they can't select item also.....

Could anyone tell me how to prevent user from entering any text in the combo box?

Thanks!

 
Hi! :)
Why would you want to do this? Let's say the combo box is a list of states. It's easier and faster for the data entry person to tab to the field and then hit the first letter(s) of the state and let it automatically fill in the rest then it would be for them to have to hit the drop down arrow on the combo box each time and scroll to the correct state. Even when is comes down to 'm' or 'f' for male of female, just tapping in the first letter is faster then forcing them to choose from the drop down list. They tab past that field and it automatically fills the rest in. Since you've limited the combo to list, they can't really enter any text anyway and the error message reminds them of this.
 
It wouldn't really prevent them from just typing something in, but adding:
Code:
me.Combo0.Dropdown

to the gotfocus event for the combobox will automatically drop down the list when it receives the focus (ie, someone tabs into it). As I said, wouldn't prevent them from typing into it, but would encourage them to select an item.
 
deadfish,

It can be done, and there can be some very compelling reasons to do it. This gets a bit messy. Sorry.

Your combo box will have a downward-pointing triangle at the right with its text box to the immediate left. Let's say the name of the combo box is cboCustomer.

1. Create a new text box called txtCustomer. It should be exactly the same size as the text box portion of cboCustomer. Delete its label. txtCustomer should be LOCKED and NOT enabled.
2. Drag the left edge of cboCustomer's text box to the right until it smashes into the downward-pointing triangle (but doesn't overlap it). You now have only the downward-pointing triangle remaining
3. Make sure cboCustomer (what's left of it anyway) is enabled and NOT locked
4. Move txtCustomer until it's in the same place as cboCustomer's text box used to be.
5. Insert the following code in the After Update event of cboCustomer (presuming the Customer ID is in Column 0 and the Customer Name is in Column 1):

Code:
Private Sub cboCustomer_AfterUpdate()
txtCustomer = cboCustomer.Column(1)
End Sub

Every time a new value is selected in the combo box (and it can be selected because the combo box is enabled and not locked), the customer name, the second column of the combo box, is placed into the text box (and looks like it's part of the combo box, but it isn't). The user can't get into this box to change the value because the box properties won't allow it, and there's no obnoxious error message to distract the user (and trigger a phone call to you).

Hope I didn't forget anything.


Dave
 
How are deadfish . . . . .

Sorry to be the one to say you can't.

Best you can do is use the [blue]NotInList[/blue] event to prompt your own message and be sure to use Me![blue]ComboboxName.UnDo[/blue] to return to normal . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top