Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Paired List Boxes info to tables

Status
Not open for further replies.

miaka13

Technical User
Jul 31, 2003
30
US
I am pretty green when it comes to Access. I've just recently started up a database for my job. I created a set of paired list boxes where you can choose an item from listbox1 and send it via a command button to listbox2. I did this because I wanted my users to be able to select multiple items. What I need help on is writing the code telling listbox2 (with the multiple selections) to send the info to a table. If anyone can help me on this I would be most grateful.

 
are you using access '97 or 2000? is the listbox populating a text box on your form? how did you tell listbox1 to populate listbox 2?
 
In response to your question, I am currently using Access 2002 and the first list box is populating a second list box. The way I got listbox1 to populate listbox2 is by using an add and remove button. The add button moves the item to listbox2. The remove button gives the user the ability to correct any mistakes that they may have made. The following is the code for the add and remove buttons:

Code:
Private Sub Add_Click()

On Error GoTo ErrorHandler

   Set lstSelected = Me![SelectedItems]
   Set lstAvailable = Me![AvailableItems]
   
   'Check that at least one item has been selected
   Debug.Print "Item count: " & lstAvailable.ItemsSelected.Count
   If lstAvailable.ItemsSelected.Count = 0 Then
      MsgBox "Please select an item"
      lstAvailable.SetFocus
      Exit Sub
   End If
   
   strItem = lstAvailable.Value
   intItem = lstAvailable.ListIndex
   
   'Add selected item to Selected Items list
   lstSelected.AddItem Item:=strItem
   
   'Delete selected item from Available Items list
   lstAvailable.RemoveItem Index:=intItem
     
ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
   Resume ErrorHandlerExit

End Sub


Private Sub Remove_Click()

On Error GoTo ErrorHandler

   Set lstSelected = Me![SelectedItems]
   Set lstAvailable = Me![AvailableItems]
   
   'Check that at least one item has been selected
   If lstSelected.ItemsSelected.Count = 0 Then
      MsgBox "Please select an item"
      lstSelected.SetFocus
      Exit Sub
   End If
   
   strItem = lstSelected.Value
   intItem = lstSelected.ListIndex
   
   'Add selected item to Available Items list
   lstAvailable.AddItem Item:=strItem
   
   'Delete selected item from Selected Items list
   lstSelected.RemoveItem Index:=intItem
      
ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
   Resume ErrorHandlerExit

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top