+ Reply to Thread
Results 1 to 11 of 11

Unable to Deselect Line In Listbox

  1. #1
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Unable to Deselect Line In Listbox

    A user selects a single item in a listbox. With the code below, I am failing at deselecting the line the user selected.

    Please Login or Register  to view this content.
    This isn't deselecting the user's selection.

  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,532

    Re: Unable to Deselect Line In Listbox

    Is multi-select set to TRUE? If not, replace your For loop with this one line:

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Unable to Deselect Line In Listbox

    Hi Jeff, thanks so much for you help.
    It isn't multiselect, so I replaced the loop with the line you suggested.

    But I'm experiencing an odd thing as a result that I can't resolve.

    The user selects an item from the list, empl_no = 0 so the message box displays. The user hits OK in the msgbox, and the message box displays again. The user hits OK again but the selection remains in the listbox.
    Clearly something wrong with my code or my approach.

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

    Re: Unable to Deselect Line In Listbox

    I forgot about one thing. When your code changes the listbox.listindex, it acts like a click, and the Sub is called again automatically.

    The textbook way to manage this is to use a variable to indicate whether events are to be processed. It looks like you already have such a variable, mbevents.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Unable to Deselect Line In Listbox

    Thanks Jeff for the suggestion. I have implemented it but experiencing the same problem.
    I've put a break at the top of the code to follow the events ..

    Follow the results of the steps ...

    empl_no tests true for equalling 0
    Message box displays
    mbevents value = false
    The selection remains highlighted in the listbox with lb_ssr.listindex = -1
    mbevents reset to true
    exit sub
    code goes back up to the first line ... Private Sub lb_ssr_Click() line.

    Code repeats itself ...

    empl_no tests true for equalling 0
    Message box displays
    mbevents value = false
    The selection remains highlighted in the listbox with lb_ssr.listindex = -1
    mbevents reset to true
    exit sub

    The routine exits at this point.

    Unsure why it is repeating.

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

    Re: Unable to Deselect Line In Listbox

    I would be happy to test this in your file if you attach it.

  7. #7
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Unable to Deselect Line In Listbox

    Hey Jeff, that's such a kind offer.

    Here is the link for the download. I use winrar, so it's in a .rar archive despite my attempts to make a .zip file. I hope this doesn't cause grief.



    To recreate.
    Place both files in a folder together. You will encounter errors as the code refers to my local file locations.
    Open StaffSched_ef.xlsm first. It will automatically open the second supportiung workbook and hiding it.
    Click the blue oval on worksheet "STAFF_FRONT". This opens a userform.

    Select one of the names in the "name" combobox. They all behave the same way.
    Puch button [View/Modify Employee Schedule]
    Select a pay period from the "Pay Period Combobox". I recommend choosing from between periods 11 and 17.
    The listbox (lb_ssr) will populate.
    Click on one of the rows in the listbox and ...

    You should experience the problem.

    Thanks again!
    Last edited by Jenn68; 03-22-2019 at 07:12 AM.

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

    Re: Unable to Deselect Line In Listbox

    I don't have anything that opens a rar file.

  9. #9
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Unable to Deselect Line In Listbox

    Try this ... its a zip file.
    Last edited by Jenn68; 03-22-2019 at 07:12 AM.

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

    Re: Unable to Deselect Line In Listbox

    I get errors all over the place no matter how I try to run this. I'll see if I can strip out the relevant code and isolate the problem.

  11. #11
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Unable to Deselect Line In Listbox

    Can I assume that no one was able to find a solution?

+ 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. Listbox does not deselect or become disabled
    By nemmi69 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-01-2017, 09:53 AM
  2. [SOLVED] Deselect all in multi-select listbox upon opening
    By ruub7 in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 06-12-2017, 06:54 AM
  3. Deselect a Listbox
    By Biplab1985 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-19-2016, 03:27 PM
  4. [SOLVED] code to deselect if empty record is clicked in listbox
    By adelkam in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-26-2015, 02:07 PM
  5. [SOLVED] Listbox Automatic Deselect Bug
    By cmore in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-05-2013, 07:36 PM
  6. How do I deselect an item from a ListBox
    By skysurfer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-27-2010, 10:59 AM
  7. Unable to fill Listbox thru VBA
    By rash in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-20-2005, 10:00 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