VBA listbox remove item unspecified error

postman2000
Student
Points379Trophies1Posts101
  • Oct 23rd 2006
  • #1

On a userform, I have a listbox named "eList" containing Employee Names.
I have 2 other listboxes named "List_eTrained" and "List_eNotTrained" which list the Training completed and Training not yet completed for the selected Employee.


When I click Name items, it updates both listboxes with information [using "AddItem"].
Before it updates, I use this code to clear the info listbox items:

Code
  1. TrainingDetails.List_eTrained.Clear
  2. TrainingDetails.List_eNotTrained.Clear


When I run the form and click on various entries, it works as expected. At random though, I get this:


Run-time error '-2147467259 [80004005]':
Unspecified error.

And only this line is highlighted in Debug mode: [COLOR="Red"]TrainingDetails.List_eNotTrained.Clear[/COLOR]


Sometimes it happens after going through several names, sometimes it happens when clicking the 2nd or 3rd name. It's only happening on the "List_eNotTrained" line though--the other line is fine--which has me really puzzled.


I'm hoping someone else has run into this before and might know what's causing this random, unspecified error..... :confused:


Thanks for any help or ideas you can provide!

postman2000
Student
Points379Trophies1Posts101
  • Oct 24th 2006
  • #3

Re: Random "unspecified Error" On "listbox.clear"


In the UserForm code, I'm launching a Module-level macro using the following code ["eList" is the listbox of names] when a list item is selected:

Code
  1. Private Sub eList_AfterUpdate[]
  2. Run "ED_selName"
  3. End Sub


"ED_selName" is a module-level macro that contains the problem code:
TrainingDetails.List_eNotTrained.Clear

postman2000
Student
Points379Trophies1Posts101
  • Oct 24th 2006
  • #5

Re: Random Unspecified Error On Listbox Clear Method


I figured it out.

[COLOR="Red"]If the ListBox RowSource property is set, using the "ListBox.Clear" command will generate that error. [/COLOR]

What was causing the random issue is that I was setting the RowSource of the problem listbox to display a range of data if certain conditions were met.

When this happened, the next person I clicked on [calling the ".Clear" command] caused the error because the RowSource of the ListBox was now set.

Sorry to bother you, but hopefully this might help others who might run into this frustrating problem...

Andy Pope
OzMVP [Roobarb]
Likes Received1Points33,975Trophies2Posts11,304
  • Oct 24th 2006
  • #6

Re: Random Unspecified Error On Listbox Clear Method


Thanks for posting the solution.


Just for information.
The reason RowSource did not get suggested as a reason is that you said you where using Additem. But you can not use Additem when Rowsource has been set.

[h4]Cheers
Andy
[/h4]

S M C
The Oracle [Expert Coder]
Likes Received2Points12,130Trophies2Posts4,036
  • Jan 27th 2011
  • #9

Re: Random Unspecified Error On Listbox Clear Method


Hi pstiglich


Welcome to Ozgrid.


DO NOT hijack threads by posting your question in thread someone else started. Always start your own thread and, if needed, provide a link back to the other thread. Please state your problem in a new thread.

Cheers,


S M C


Click To Read: How To Use Tags In Your Threads/Posts
Please take time to read Forum Rules before posting
Message To Cross Posters

Video liên quan

Chủ Đề