Combo Box Problem-VBForums
Results 1 to 6 of 6

Thread: Combo Box Problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2010
    Posts
    462

    Combo Box Problem

    Hi,

    How do you control the default combo box (the visible) text?

    I'm having trouble.... it retains the last value which means it needs to be re-selected to fire the Change event, if you want that item.

    Sorry if that doesn't make sense.... after 3 days trying to sort this - major stress is paramount !

    Thanks...

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    20,003

    Re: Combo Box Problem

    it retains the last value which means it needs to be re-selected to fire the Change event, if you want that item.
    yes that would be correct
    please detail what you want to do, what result you are trying to achieve
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2010
    Posts
    462

    Re: Combo Box Problem

    Hi Pete,

    The Row source is Worksheet!b6:b9 and control Source b5 - a cell containing "Please Select". When the Form opens I wanted that showing in the text area, with the dropdown to list the four list options.
    The change event displays a label and textbox for the next stage (not done yet).

    This works the first time only. Once an item is selected that replaces b5 and becomes what's shown in the text box next time - also fireing the change event early.

    Attempting to reset cbo.value to "" or "Please Select" caused "Could not set the Value property. Invalid property value." Changing b5 back to "Please Select" in code didn't work.. in either Form Close or Sub Demo, which calls the Form. But typing it back in manually to b5 did.

    I can ditch the combo box and perhaps try radio buttons, but I'm curious why it 's so problematic and it'd be good to know what I'm doing wrong for future use. There's a wee xls which demo's it if you'd like to look further.

    http://dl.dropbox.com/u/49222457/cboDemo.xls
    Thanks, ABB

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    20,003

    Re: Combo Box Problem

    i think you are using control source incorrectly, i would include b5 in the rowsource instead

    then something like
    vb Code:
    1. If cboBE.Text = "Please Select" Then Exit Sub
    2. If InStr(Join(Application.Transpose(Worksheets("Config").Range("B6:B9")), ""), cboBE) > 0 Then
    3.     lblBackend.Visible = True
    4.     txtBackend.Visible = True
    5. Else
    6.     lblBackend.Visible = False
    7.     txtBackend.Visible = False
    8. End If
    9. cboBE.ListIndex = 0
    i would prefer to use the click event rather than the change event
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2010
    Posts
    462

    Re: Combo Box Problem

    Hi Pete, thanks for the reply.

    Quote Originally Posted by westconn1 View Post
    i think you are using control source incorrectly, i would include b5 in the rowsource instead
    Right.. but doing that would see 'Please Select' prompt become an option in the list ?

    i would prefer to use the click event rather than the change event
    Changed to the click event and applied your revised code. But still don't get the Prompt as the default text value. That's now blank. I added .Dropdown which may be nicer... not sure. I can't figure out yet how to have an item highlit, it just has the marquee around it, which looks sort of wrong.

    Having 'Select' as the default and only the four choices in the list would be ideal. Is that not possible ? If so I'll add a label for the Prompt.

    Cheers, ABB

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    20,003

    Re: Combo Box Problem

    Right.. but doing that would see 'Please Select' prompt become an option in the list ?
    yes, but with the code above, it does nothing when selected

    you can not set a value for cbo text when using a rowsource, works if you create a list using additem
    i do not see why it would not work as you have requested
    you could also move the code setting the listindex to some other appropriate procedure
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.