+ Reply to Thread
Results 1 to 10 of 10

Removing item from one listbox to another Code Issue

  1. #1
    Registered User
    Join Date
    01-17-2013
    Location
    canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Removing item from one listbox to another Code Issue

    Hey there,

    Love these forums, so helpful!

    Here's my (new) issue. I have 2 list boxes: left one with existing brands and right one with selected brands. The user clicks on the item in the left box, presses the command button, and the item goes to the right box...No problem there. THE PROBLEM: What is wrong with my code below is the item from the left hand side should be removed when it is commanded to the right hand side. In other words, my selected item is moving to the right side box, but not deleting itself from the left side box!

    Thanks for any help...

    The error code I get is with the following line:

    FrmNewSeason.lstExistingBrands.RemoveItem iCtr

    Code:

    Please Login or Register  to view this content.
    Cheers for any help or insight!!

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

    Re: Removing item from one listbox to another Code Issue

    What's the error message?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-17-2013
    Location
    canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Removing item from one listbox to another Code Issue

    Hey Norie, thanks for inquiry,

    Run time error, unspecified error--Then it highlights the following line:


    FrmNewSeason.lstExistingBrands.RemoveItem iCtr

  4. #4
    Registered User
    Join Date
    01-17-2013
    Location
    canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Removing item from one listbox to another Code Issue

    Could it be because the left side list, lstExistingBrands, is populated by the properties RowSource, and not populated on activate?

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

    Re: Removing item from one listbox to another Code Issue

    Populating the listbox is probably the problem.

    When you use RowSource to populate listboxes it kind of restricts what you can do because they are linked back to a range.

    Where/when are you populating the listbox?

    Instead of RowSource you could use List to populate it.

    You can actually use the RowSource's address if you do that.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-17-2013
    Location
    canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Removing item from one listbox to another Code Issue

    Hey Norie, thanks for the input. I also think it's not responding to remove because I have populated the list from properties when the FrmNewSeason opens.

    I have changed my code as shown below...now however, I'm not getting any response from my Rowsource...Nothing is popping up in the left side list box!!

    Code to activate list when I click on button btn_NewSeason:

    Please Login or Register  to view this content.
    Code to pass selected tems from left to right:


    Please Login or Register  to view this content.
    Thanks again for any input!

  7. #7
    Registered User
    Join Date
    01-17-2013
    Location
    canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Removing item from one listbox to another Code Issue

    Nevermind...Got it to work..Indeed, adding that one line you suggested on userform activate has solved this issue..Thank you very much Norie for your simple and wse input!!

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

    Re: Removing item from one listbox to another Code Issue

    Is the sub FrmNewSeason_Activate meant to run when the userform FrmNewSeason is activated?

    If you want code to run when the userform opens try this.
    Please Login or Register  to view this content.
    You could use UserForm_Activate but that will be triggered every time the userform is activated.

    By the way, if you were using Brands as the row source you could use this to populate the listbox.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    01-17-2013
    Location
    canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Removing item from one listbox to another Code Issue

    Both of those work indeed...I was activating the wrong userform!! (roll eyes!!)

    Thank you very much for your time and help!

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

    Re: Removing item from one listbox to another Code Issue

    Glad you got it working.

    By the way, this code wouldn't run when activating any userform.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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