Results 1 to 4 of 4

Thread: combo1_change question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2000
    Location
    BC, Canada
    Posts
    142

    Post

    It sounds simple, but still needs help

    I have a combobox with the style of dropdown list. I want some events fired when the user change the list selection.

    Common sense leads me to following code

    Private sub Combo1_change()
    msgbox "selection is changed"
    end sub

    But it doesn't work. MSDN says:
    -------------------
    ComboBox — changes the text in the text box portion of the control. Occurs only if the Style property is set to 0 (Dropdown Combo) or 1 (Simple Combo) and the user changes the text or you change the Text property setting through code.
    -------------------
    Other events such as _lostfocus, _keypress and _click are not working for my purpose.

    Any help? thx!



  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    If the click event is firing, you can just call your change event code from there.
    Code:
    Private Sub Combo1_Click
       Call Combo1_Change
    End Sub
    Wade

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2000
    Location
    BC, Canada
    Posts
    142

    Post Thx

    Thanks very much WadeD! It is great!

    I have another question here.
    For the following code

    <code>Private sub combo1_change()
    msgbox combo1.text
    end sub

    private sub combo1_click()
    msgbox combo1.text
    call combo1_change
    end sub</code>

    Both msgbox show new Text, anyway to know original text?
    Since in my application, some of combo list are not allowed to be changed, I need a way to identify these items and if true, set the text back to original

    thanks so much for help

  4. #4
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    Since the only event firing without your intervention is the combo1_click event, I'm guessing that the user can only select values from the combo (not type in a value) and you don't want them to do this in certain instances. If you want to temporarily disable them from selecting a different value, use combo1.enabled = false

    If you do want to keep the combo enabled, use this:
    Code:
    'Declare bAllowChanges as a Public Variable Indicating if Changes Are Allowed Right Now
    
    Private Sub Combo1_Change
    If bAllowChanges = True Then  
       'Store Value
       Combo1.Tag = Combo1.ListIndex
    Else
       'Warn User, Reset Value
       Msgbox "This Item May Not Be Changed.", vbOkOnly + vbInformation, "Invalid Entry"
       Combo1.ListIndex = Combo1.Tag  
    End If
    Wade

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