Lock combo boxes from user input?
I need to restrict user input on a combo box while still allowing them to select an item from the drop down menu. I know this can easily be achieved by setting the style to VbComboDrop-DownList, however this will not work for me.
Here is the scenario.
When a user loads a new form, information from an access database populates my combo boxes. As the user changes different items on the form, the combo boxes re populate, and in some cases, show a default value.
Example:
User selects natural gas as their fuel type. The units drop down menu only lists MCF, CCF, DTH. If the user selects electric as their fuel type, the units drop down menu switches to KWH, MWH. This is all fine while setting the combo box to be a VbComboDrop-DropList.
The user is able to save this information. Upon reloading the form, the saved information is pulled in as the default values for the combo boxes (ie, what they previously selected is what shows up in the combo box as a selected item). To do this, I had the combo boxes populate as I normally would, and then I did cmbUnits.text = glbHeatingFuelUnits.
Now, if I set the combo boxes to VbComboDrop-DropList, I am unable to use the .text property to select and display what they chose and saved before. I tried setting the property from VbComboDropDown when loading the form so the information could be displayed, and then locking it after it loads with the VbComboDrop-DropList style setting but I receive a read only error.
So basically, how can I lock these combo boxes from user input while still allowing the program to display values I previously saved in them?
--> FUTURE PROBLEM ::: Also, there is a chance that a user will save an item that will eventually be removed form my database, and therefore will not be listed in the combo boxes options, however I still want that item to show even though its not in the drop down list.
Re: Lock combo boxes from user input?
Set the style propertie to 2 - Dropdown List.
Btw... welcome to the forums :wave:
Re: Lock combo boxes from user input?
Thanks but I covered that. It will not work for my situation.
Re: Lock combo boxes from user input?
Welcome to the forums. :wave:
Set the combo style to Dropdown Combo so the text property is available to you. Then trap all keystrokes so they can't actually type in it by adding this
VB Code:
Private Sub Combo1_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub
Re: Lock combo boxes from user input?
Re: Lock combo boxes from user input?
At Form_Load, add the items from your database. If the saved information has an item not in the database, .AddItem that item. Set the .ListIndex to whichever item you want showing.
Re: Lock combo boxes from user input?
The other suggestion worked perfectly. Thanks!