|
-
Aug 3rd, 2006, 01:04 PM
#1
Thread Starter
Junior Member
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.
Last edited by Arin; Aug 3rd, 2006 at 01:09 PM.
-
Aug 3rd, 2006, 01:06 PM
#2
Re: Lock combo boxes from user input?
Set the style propertie to 2 - Dropdown List.
Btw... welcome to the forums
-
Aug 3rd, 2006, 01:07 PM
#3
Thread Starter
Junior Member
Re: Lock combo boxes from user input?
Thanks but I covered that. It will not work for my situation.
-
Aug 3rd, 2006, 01:10 PM
#4
Re: Lock combo boxes from user input?
Welcome to the forums. 
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
-
Aug 3rd, 2006, 01:11 PM
#5
Thread Starter
Junior Member
Re: Lock combo boxes from user input?
-
Aug 3rd, 2006, 01:15 PM
#6
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.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Aug 3rd, 2006, 02:45 PM
#7
Thread Starter
Junior Member
Re: Lock combo boxes from user input?
The other suggestion worked perfectly. Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|