+ Reply to Thread
Results 1 to 13 of 13

Copy item from one listbox to another

  1. #1
    Registered User
    Join Date
    09-06-2010
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    96

    Copy item from one listbox to another

    Hi folks

    I am writing the following code to add or remove the items from one listbox to another. But my problem is suppose one user adds item A from listbox1 to listbox2 and again select item A and click on button then it again appears in listbox 2 so if the user does it for 10 times then 10 times same item A appears in Listbox2 which is not right so one item should be present once only in other listbox and multiple copy should not be allowed.

    Please Login or Register  to view this content.
    Thanks

  2. #2
    Forum Contributor wamp's Avatar
    Join Date
    11-10-2008
    Location
    Norway
    MS-Off Ver
    97, 2000 & 2003 (diff. workstations)
    Posts
    184

    Re: Copy item from one listbox to another

    probably not the best solution, but why not loop through the items in listbox2 to check if the selected item allready exists?

    Let's say you have 2 listboxes named listbox1 & listbox2..
    when a user clicks on an item in listbox1, run the following code

    Please Login or Register  to view this content.
    _______________________________________________
    Remember:

    Read the rules!

    Use code tags! Place [CODE] before the first line of code and [/CODE] after the last line of code.

    Mark your post [SOLVED] if it has been answered satisfactorily.
    To do this, click EDIT in your original post, click GO ADVANCED and set the PREFIX. It helps everybody!

    If you are approve (or disapprove) of any members response to your problem, please click the star icon underneath their post and comment. It matters.

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,646

    Re: Copy item from one listbox to another

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-06-2010
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    96

    Re: Copy item from one listbox to another

    Hi snb

    I don't want to remove the item from listbox2 as listbox2 has got all the permissions and the user can give permissions from listbox2 to listbox3.

    I just want, not to add the same item from listbox2 to listbox3 multiple times that means if item ABC exist in listbox2 and we click on button then it appears in listbox3 but if again we select the item ABC from listbox2 then it should not appear in listbox3 multiple items and instead display a message this permission has already been given to the user.

    Thanks

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,646

    Re: Copy item from one listbox to another

    Moving items to combobox 3 doen't imply the loss of permissions for the user that attributes the permissions.

  6. #6
    Registered User
    Join Date
    09-06-2010
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    96

    Re: Copy item from one listbox to another

    Hi snb

    Actually in the form there are 3 listboxes:
    1. The listbox1 refers to all the user names.
    2. The listbox2 referes to your permissions as you can give only those permissions to other users.
    3. when we select any username from listbox1 and any item from listbox2 and then click on a button then that item appears in listbox 3 as well. Now that means the selected user has now given this permission.

    So I just want a code that will not allow to copy same item from listbox2 and addin listbox3. Just give an error message that this permission has already been given to the selected user.SO not allow to add same item multiple times in listbox3. But also don't remove any item from listbox2 as well. Because the listbox2 has a list of all the permissions that you have and listbox3 will store the permissions for the selected user .

    Thanks

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,646

    Re: Copy item from one listbox to another

    After storing the permissions for a user the listbox2 can be refreshed in order to contain all permissable items.
    I prefer not to bother users with messageboxes. It looks as if the user did something 'wrong' (it's better preventing actions that you will not allow); that can be prevented using my code.

  8. #8
    Registered User
    Join Date
    09-06-2010
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    96

    Re: Copy item from one listbox to another

    snb, I think there is some communication gap. Actually may be i didn't make my problem clear to you. My problem is once item ABC appears in listbox3 then if the user again selects ABC from listbox2 and press add button then it should n't appear in listbox 3 as the listbox 3 has already go item ABC. SO just want a validation on listbox3 that will check all the items before adding any new item. If the item already appears in listbox3 then don't do anything otherwise add it in listbox3.

    Please advice me.

    Thanks

  9. #9
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Copy item from one listbox to another

    There's definitely a communication gap - you aren't listening to what snb is saying.
    Remove the item when selected and then when the permissions are applied reset the contents of the first listbox.
    Remember what the dormouse said
    Feed your head

  10. #10
    Registered User
    Join Date
    09-06-2010
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    96

    Re: Copy item from one listbox to another

    Ok If I do this then again the user selects an item from the listbox2 that also appears in listbox3 and press add button then what will happen???????

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Copy item from one listbox to another

    They can't - the item won't be in Listbox2 for them to select.

  12. #12
    Registered User
    Join Date
    09-06-2010
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    96

    Re: Copy item from one listbox to another

    No I don't want it in reality. If I am logged into the system then listbox2 will show all permissions given to me and now its upto me what permission I should give to the selected user from listbox1. I just want a validation in listbox3 that will check the selected listbox2 item and if its present in the listbox3 then don't add it otherwise add it.

    I am looking for something else: a cvalidation on listbox3??????

    Thanks

  13. #13
    Registered User
    Join Date
    09-06-2010
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    96

    Re: Copy item from one listbox to another

    finally solved my problem:
    Please Login or Register  to view this content.
    Thanks guys.

+ 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