Results 1 to 7 of 7

Thread: Lock combo boxes from user input?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Posts
    17

    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.

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Lock combo boxes from user input?

    Set the style propertie to 2 - Dropdown List.

    Btw... welcome to the forums

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Posts
    17

    Re: Lock combo boxes from user input?

    Thanks but I covered that. It will not work for my situation.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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:
    1. Private Sub Combo1_KeyPress(KeyAscii As Integer)
    2. KeyAscii = 0
    3. End Sub

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Posts
    17

    Re: Lock combo boxes from user input?

    Excellent!

    Thank you :-)

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Posts
    17

    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
  •  



Click Here to Expand Forum to Full Width