+ Reply to Thread
Results 1 to 6 of 6

Curious Results from DblClick Event running on a ListBox in a Userform

  1. #1
    Registered User
    Join Date
    09-28-2016
    Location
    Sydney, Australia
    MS-Off Ver
    2011
    Posts
    16

    Curious Results from DblClick Event running on a ListBox in a Userform

    I have a userform with a listbox (shown below) that is populated from a spreadsheet (cc_output) generated by an advanced filter.

    I am trying to write some code so that when you double click on a record in the listbox a lookup is performed on the spreadsheet (cc_output) to find the matching record and populate all of the data in some comboboxes in the userform.

    I am trying to look up using the cc_id which is in the first column of the listbox and which is stored in column A of the spreadsheet cc_output.

    This is working perfectly for records with cc_id 17 to 8 in the listbox but when I click on any records with cc_id 7 - 1 they return the wrong record from the spreadsheet.

    That is

    Double clicking cc_id 17 returns cc_id 17
    Double clicking cc_id 16 returns cc_id 16

    but...

    Double clicking cc_id 7 returns cc_id 17
    Double clicking cc_id 6 returns cc_id 16

    and so on... until...

    Double clicking cc_id 1 returns cc_id 17 also!


    ListBox.PNG

    Here is an excerpt of my code:

    Please Login or Register  to view this content.
    Any ideas?

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Curious Results from DblClick Event running on a ListBox in a Userform

    Did you already try this ?
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Curious Results from DblClick Event running on a ListBox in a Userform

    Have you tried using Application.Match to find the row in A that the id is in?

    You could then use that to populate the other controls.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    09-28-2016
    Location
    Sydney, Australia
    MS-Off Ver
    2011
    Posts
    16

    Re: Curious Results from DblClick Event running on a ListBox in a Userform

    Sincere thanks! This appears to have solved the problem.

    I'm not sure I fully understand why though... What was happening during the lookup before that is not happening now?

  5. #5
    Registered User
    Join Date
    09-28-2016
    Location
    Sydney, Australia
    MS-Off Ver
    2011
    Posts
    16

    Re: Curious Results from DblClick Event running on a ListBox in a Userform

    I added: LookAt:=xlWhole to Find() and this all works now.

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Curious Results from DblClick Event running on a ListBox in a Userform

    xlWhole means the text you are searching for must fill the whole cell; in other words, all the text in the cell must be the same as the text you are searching for.

    xlPart means the text you are searching for only needs to be part of the text in the cell... there can be additional text in the cell along with the text you are searching for.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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] DblClick event on listbox crashes Excel when I move the listbox as a result of the event
    By feanturi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-22-2022, 11:38 AM
  2. DblClick from listbox to textbox
    By prinsr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-05-2017, 02:48 AM
  3. [SOLVED] Unable to remove item with dblclick in listbox
    By ImranBhatti in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-28-2017, 11:40 AM
  4. populate textboxes from listbox dblClick
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-24-2017, 08:06 AM
  5. [SOLVED] Userforms - same dblclick event for multiple controls
    By rodgersmg in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-17-2015, 06:06 AM
  6. Editing listbox items in Dblclick event freezes Excel unless mouse moves over listbox
    By muneebmansoor in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-28-2013, 02:21 PM
  7. DblClick event does not work with combobox?
    By marcusr in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-27-2007, 07:44 AM

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