Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2003
    Posts
    68

    Question Unanswered: HELP! Take selected items from one list box to another list box

    I'm trying to move selected items from one unbound list box to another list box, but also update a table with that data that was selected.
    NEED HELP Not sure why what I'm trying doesn't work.
    jm
    jm

  2. #2
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    if you could give some more details what you are really trying to do, I could try to help you.
    ghozy.

  3. #3
    Join Date
    Aug 2003
    Posts
    68
    Trying to let the user select states from one list box Click a button to move the selected states over to a new list box and then use those states selected in a SQL statement. But I want to store the selection so that if someone later wants to use that same selection they can use it. So I have a profile table that stores the selected states, and other such data for the SQL statement.
    jm

  4. #4
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    do you want to move or to copy the selection?
    ghozy.

  5. #5
    Join Date
    Aug 2003
    Posts
    68
    Move or Copy...It can be dragged or clicked by a button.
    as long as the table is updated, it shouldn't matter.
    thanks for you help in advance
    jm

  6. #6
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    Okay, we have 2 listboxes. ListboxA keeps the list of States, and ListboxB linked to a table that keeps list of the selected states which I will call it as Table2. Table2 have a field called States, which will keep list of the previously selected States for us.
    Add a button and copy this code into its event code:
    Code:
     
    Dim ADOCon As ADODB.Connection
    Dim Selected As Variant
    Dim State As String
    Set ADOCon = Application.CurrentProject.Connection 'get the current ADO connection
    For Each Selected In ListboxA.ItemsSelected	 'a loop for every selected item in the listboxA
    	State = ListboxA.ItemData(Selected)	 'get the state name by index number
    	 'check if selected state is already in the table. if it is skip to next state
    	If Not IsNull(DLookup("states", "table2", "states='" & State & "'")) Then GoTo NextState
    	 'not in the list then add it to the table2
    	ADOCon.Execute ("INSERT INTO table2 (states) values('" & State & "')")
    NextState:
    Next
    ListboxB.Requery	'requery listboxB so we can see the transfer
    I hope that works.
    ghozy.

  7. #7
    Join Date
    Aug 2003
    Posts
    68
    That works. I think I can figure out the rest. I need all selected state codes to be in one record ie AK,AL,MI instead of in different records. Thats all.
    That will make the SQL string easier to produce.
    thanks
    jm
    jm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •