+ Reply to Thread
Results 1 to 16 of 16

ComboBox Erratic Behavior

  1. #1
    Forum Contributor
    Join Date
    09-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2013
    Posts
    222

    ComboBox Erratic Behavior

    When I put the code below in a UserForm (VBA Editor) it works as it should but when I use an ActiveX combobox in an ActiveX worksheet where I keep the remaining control, sometimes works well and sometimes it does not

    Please Login or Register  to view this content.
    The lesson I follow says to doubleclick the cboSelect control and in the code window which will open to choose “Initialize”. But since I use an ActiveX control the only option I have is to write the code manually. If I choose a Form combobox in my ActiveX form the only option I have is to assign a Macro

    How can I make it work?

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,717

    Re: ComboBox Erratic Behavior

    The lesson I follow says to doubleclick the cboSelect control and in the code window which will open to choose “Initialize”.
    That doesn't make sense. Is this exactly what your lesson says? If you double-click on the control, it will open the code window. There is no option to "choose" and there is no Initialize event for a combobox; I think you are confusing it with Initialize for a form. For a form, it may be directing you to create a sub called

    Please Login or Register  to view this content.
    which is usually where you will set up your combo box. The code you showed above will set up the combo box every time someone makes a selection, which is not the correct way to do it.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    09-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2013
    Posts
    222

    Re: ComboBox Erratic Behavior

    Very sorry Jeff, you are right the lesson says to doubleclick the userform and choose view code and from the top right hand corner click the drop down arrow for the events and select "Initialize". Then to add this code
    Please Login or Register  to view this content.
    But by having ActiveX form with all my controls I dont have UserForm to doubleclick. So where and how to put this code for the combobox?

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: ComboBox Erratic Behavior

    I think you need to give more information as to what happens when your code doesn't "work well".

    FYI if you have an activex control on a worksheet, in the code editor you can select the control name from the left hand drop down and the relevant events will be listed in the right drop down, just like on a userform.
    Remember what the dormouse said
    Feed your head

  5. #5
    Forum Contributor
    Join Date
    09-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2013
    Posts
    222

    Re: ComboBox Erratic Behavior

    The Range("B8:O8")) in the combobox is for the 14 headers I have in my db (LastName, FirstName, etc.). When I click on the arrow in the combobox a list drops down with the names and I click anyone I want to do a search. Sometimes when I click the drop down arrow nothing happens I mean there is no list or the space for the list and sometimes all the names are there. But once the list is there it stays and works well until I close the file. Then if the list does not work I go to the VBA editor, delete / re write the above mentioned code a few times and then it works again. Thanks for the help

  6. #6
    Forum Contributor
    Join Date
    09-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2013
    Posts
    222

    Re: ComboBox Erratic Behavior

    I tried this code and looks like it works fine so far

    Please Login or Register  to view this content.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,717

    Re: ComboBox Erratic Behavior

    The Initialize Sub associates your combobox with a list of data used to populate it. It is called the first time that the userform is displayed, and will "stick" for the rest of the life of the session.

    The DropButtonClick Sub says what's going to happen every time the user clicks on the dropdown. You don't need to keep resetting the list range every time the user clicks--it only needs to be done once, in the Initialize sub. Doing it here doesn't hurt anything but it doesn't do anything useful, either.

  8. #8
    Forum Contributor
    Join Date
    09-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2013
    Posts
    222

    Re: ComboBox Erratic Behavior

    Very good info StringJazzer thank you, now I know the difference and looks like that I must find a way to Initialize it. But since this is an ActiveX control how I can do that?

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,717

    Re: ComboBox Erratic Behavior

    The code for Initialize you have already done and it's fine

    The code for DropButtonClick is unnecessary and can be removed.

  10. #10
    Forum Contributor
    Join Date
    09-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2013
    Posts
    222

    Re: ComboBox Erratic Behavior

    When I REM out the DropButtonClick the comboSelect button is not working (I don't see the list anymore)

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,717

    Re: ComboBox Erratic Behavior

    It is really difficult to help with this just getting bits and pieces here and there.

    Here is a sample file with your code that works. There is no Sub for DropButtonClick. See how this compares to yours. To get further help you're going to have to attach your file.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    09-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2013
    Posts
    222

    Re: ComboBox Erratic Behavior

    Thanks for your time. I don't have much experience with VBA but I would say your file is with Form control and mine is with ActiveX. I had downloaded my workbook on this thread

    http://www.excelforum.com/showthread...94#post4071694

    Please look in my post #5 on the above link to get the download. The combobox is at the top left of the form under the label Select Field

  13. #13
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,717

    Re: ComboBox Erratic Behavior

    the lesson says to doubleclick the userform
    It sounds like your assignment is to create a UserForm. But you do not have a UserForm in this file. Instead you are using a worksheet to create a form. That's certainly a valid way to get information from a user, but that's not what your assignment says to do.

    The Initialize event is associated exclusively with UserForm. That's why it doesn't work when you try to put it in a worksheet.

    My example uses ActiveX controls on a UserForm. The UserForm is the thing that pops up when you click the button. All controls in a UserForm are ActiveX.

  14. #14
    Forum Contributor
    Join Date
    09-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2013
    Posts
    222

    Re: ComboBox Erratic Behavior

    I did complete the lesson with a UserForm but then I got more adventurous and decided to make my own ActiveX form to see the difference. Now that you pointed out, I agree the Initialize was for a UserForm. This is a hobby project to learn VBA and your help is appreciated

  15. #15
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,717

    Re: ComboBox Erratic Behavior

    Your code reloads the combobox every time the user touches it. In purely practical terms, it works and doesn't do anything wrong. But from a coding practice standpoint, you are doing something repeatedly that only needs to be done once. This could be done, for example, by using the Workbook_Open event in the workbook, which will load the combobox once when the workbook is first opened. In some cases, this would make a significant difference in performance and response time.

  16. #16
    Forum Contributor
    Join Date
    09-29-2014
    Location
    Montreal, Canada
    MS-Off Ver
    2013
    Posts
    222

    Re: ComboBox Erratic Behavior

    Good to know StringJazzer, when my knowledge improves I will try the Workbook_Open event. Thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Erratic User Form Command Button behavior
    By RonRich in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-30-2013, 11:32 AM
  2. Seemingly erratic behavior when auto-filling cells
    By excelforum123 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-22-2010, 07:16 AM
  3. Erratic behavior from Excel 2000
    By dkolars in forum Excel General
    Replies: 1
    Last Post: 01-23-2009, 12:54 PM
  4. [SOLVED] erratic listbox behavior
    By Mark Olsen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-07-2006, 09:20 AM
  5. [SOLVED] Erratic Cursor Behavior
    By Cathy C in forum Excel General
    Replies: 6
    Last Post: 06-18-2005, 12:05 PM

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