+ Reply to Thread
Results 1 to 10 of 10

ListBox automatically selects an item when user form opened

  1. #1
    Registered User
    Join Date
    11-25-2018
    Location
    Scotland
    MS-Off Ver
    2010
    Posts
    7

    ListBox automatically selects an item when user form opened

    I thought I had fixed this issue which I posted about yesterday, but it turns out I hadn't!

    I have uploaded the Excel file so you can see the issue (please see next post in the thread - it failed to upload first time).

    The problem is that there are what I can only describe as 'phantom' clicks on list boxes when a user form is shown.

    To replicate this issue:
    Click on the Test Button

    In the 'Start Here' form that appears, click on 'Setting Up'

    Then, one of two things will likely happen:
    Either the third item in the listbox in the form that next appears will be selected and highlighted
    or
    A MessageBox will appear. This MsgBox should only appear after the user clicks on the third item in the listbox in the 'Setting Up Stock Descriptions and Locations' form.

    Neither of these is what I want - the 'phantom' selecting.

    The problem has been intermittent, so please do run the sequence a couple of times if it behaves itself initially.

    Similar problems occur if you choose the 'Maintaining stock levels' listbox option from the first user form.

    I have tried inserting several ListBox Clear and ListIndex = -1 instructions, but nothing seems to work permanently.

    Any help much appreciated.
    Last edited by Xtab; 11-26-2018 at 04:17 AM. Reason: Attachment not uploaded

  2. #2
    Registered User
    Join Date
    11-25-2018
    Location
    Scotland
    MS-Off Ver
    2010
    Posts
    7

    Re: ListBox automatically selects an item when user form opened

    File attached now (I hope).
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,003

    Re: ListBox automatically selects an item when user form opened

    Quote Originally Posted by Xtab View Post
    File attached now (I hope).
    I tried your workbook & you're right 'the phantom selecting' happened as you described.
    I don't know what is the source of the problem, I guess the sequence between Me.Hide and SettingUp.Show is too fast, somehow it makes the cursor focus unclear.
    So I experimented by adding this blueline between them:

    Please Login or Register  to view this content.
    and then 'the phantom selecting' didn't happen anymore.
    Just try it.

  4. #4
    Registered User
    Join Date
    11-25-2018
    Location
    Scotland
    MS-Off Ver
    2010
    Posts
    7

    Re: ListBox automatically selects an item when user form opened

    Many thanks. That certainly worked.

    I tweaked it down to 1 second. Is it possible to reduce the delay even further, do you know? I know there's a chance that if the delay is too short, the problem will re-occur, but it's be nice if the delay was absolutely minimal.

  5. #5
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,003

    Re: ListBox automatically selects an item when user form opened

    Quote Originally Posted by Xtab View Post
    Many thanks. That certainly worked.

    I tweaked it down to 1 second. Is it possible to reduce the delay even further, do you know? I know there's a chance that if the delay is too short, the problem will re-occur, but it's be nice if the delay was absolutely minimal.
    Hm..., ok try this other method, using DoEvents.

    Please Login or Register  to view this content.
    But if it works (or doesn't work), please don't ask me about DoEvents, because to be honest I have an unclear understanding of it.

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: ListBox automatically selects an item when user form opened

    Personally, I would suggest you don't use a listbox event at all to show the second form, but use a button instead. That would also be less annoying if a user accidentally selects the wrong item in the list.
    Rory

  7. #7
    Registered User
    Join Date
    11-25-2018
    Location
    Scotland
    MS-Off Ver
    2010
    Posts
    7

    Re: ListBox automatically selects an item when user form opened

    Quote Originally Posted by Akuini View Post

    But if it works (or doesn't work), please don't ask me about DoEvents, because to be honest I have an unclear understanding of it.
    Sadly, that reinstated the issue, but thanks for the thought. I'd guess that it might be that there are no events to 'Do', so there isn't enough delay. I could probably add in a Call that does some work (e.g. counting from 0 to whatever) and this might make the DoEvents route work. But that's getting a bit ugly

  8. #8
    Registered User
    Join Date
    11-25-2018
    Location
    Scotland
    MS-Off Ver
    2010
    Posts
    7

    Re: ListBox automatically selects an item when user form opened

    Quote Originally Posted by rorya View Post
    Personally, I would suggest you don't use a listbox event at all to show the second form, but use a button instead. That would also be less annoying if a user accidentally selects the wrong item in the list.
    Thanks, Rory.

    I'm pretty sure that in the many things I tried the past two days, I did include the Confirm Button route. But I think that didn't resolve the issue. But I'll try it again, just in case.

    Double-clicking on the list box seems to work, using the DblClick event handler, but it's not the most intuitive - even with a label telling the user to double click. Even though it's my app, I still found myself clicking once and momentarily wondering why nothing happened!

    OptionButtons seem to work without this issue as they can be cleared by setting values of all to False.

    But I just don't like being defeated by the pesky List Box.

  9. #9
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,003

    Re: ListBox automatically selects an item when user form opened

    Quote Originally Posted by Xtab View Post
    Sadly, that reinstated the issue, but thanks for the thought. I'd guess that it might be that there are no events to 'Do', so there isn't enough delay. I could probably add in a Call that does some work (e.g. counting from 0 to whatever) and this might make the DoEvents route work. But that's getting a bit ugly
    First, I actually tested the code & it worked, so I don't know why it didn't work for you.
    Second, I agree with rorya, it is easier & also more common to do the job by using a command button not a listbox.

  10. #10
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: ListBox automatically selects an item when user form opened

    I'd be very surprised if a button had the same problem, and equally so if a double-click event didn't have the original issue on occasion.

+ 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. User Form ListBox - Find Records (ListBox Populating Issue)
    By LONeillSSC in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-20-2015, 12:06 PM
  2. Print preview from user form opened from a user form
    By Brunstgnegg in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-13-2011, 05:12 AM
  3. Transfer User form data to a worksheet w.r.t. combobox item on the form
    By nm766 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2011, 12:43 PM
  4. linking a list item or text item in a user form to a worksheet
    By ravergirl7216 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-03-2010, 03:43 AM
  5. Listbox-user selects the values
    By cshm in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-26-2007, 01:17 PM
  6. Can a user form be opened from a macro??
    By mike703 in forum Excel General
    Replies: 1
    Last Post: 07-06-2006, 04:30 PM
  7. User form error when opened
    By theguz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-24-2005, 08:09 AM

Tags for this Thread

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