+ Reply to Thread
Results 1 to 3 of 3

UserForm ComboBox Change Event Question

Hybrid View

tja1964 UserForm ComboBox Change... 05-10-2012, 06:16 PM
JosephP Re: UserForm ComboBox Change... 05-10-2012, 06:37 PM
tja1964 Re: UserForm ComboBox Change... 05-10-2012, 07:21 PM
  1. #1
    Registered User
    Join Date
    07-26-2009
    Location
    Vancouver, Canada
    MS-Off Ver
    Excel 2002
    Posts
    14

    UserForm ComboBox Change Event Question

    I was wondering, can you give a combobox a value i.e. Me.ComboBox1.ListIndex = 0 and not have the ComboBox change event fire unless the value gets changed?

    Private Sub test()
    Me.combobox1.RowSource = "ComboTypes"
    Me.ComboBox1.ListIndex = 0
    End Sub
    
    Private Sub ComboBox1_Change()
    'do stuff if value is changed
    End Sub
    
    Private Sub ComboBox2_Change()
    'do more stuff
    End Sub
    I'm finding that since I'm giving a value to ComboBox1, the focus switches to ComboBox2 without user interaction. I would like ComboBox1 to have focus and wait till the user presses the enter button, or clicks combobox2 with the mouse (acknowledging that combobox1 has the correct default value). Is that possible?

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: UserForm ComboBox Change Event Question

    you need to use a variable as a flag to skip the change code
    Dim bNoEvents as Boolean
    Private Sub test()
    Me.combobox1.RowSource = "ComboTypes"
    bNoEvents = True
    Me.ComboBox1.ListIndex = 0
    bNoEvents = False
    End Sub
    
    Private Sub ComboBox1_Change()
    If bNoEvents then Exit Sub
    'do stuff if value is changed
    End Sub
    
    Private Sub ComboBox2_Change()
    If bNoEvents Then exit sub
    'do more stuff
    End Sub
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    07-26-2009
    Location
    Vancouver, Canada
    MS-Off Ver
    Excel 2002
    Posts
    14

    Re: UserForm ComboBox Change Event Question

    Thanks again JosephP for helping me out and quickly at that!!!

    Have a nice day.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1