Results 1 to 7 of 7
  1. #1
    macaulayrg2003 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    6

    Unhappy Multiple slection from a list box / combo box then put the selction into a form

    I have a table of perssonel. I wish to be able to select either 1, 2 or 3 etc then put that seclection into a form. can this be done. I have tried to make a list box, combo box but cannot make multiple selection even though I have multi value selected on the look up propreties.

    this is my basics table


    ID Personnel
    1 SSHP
    2 Ships Staff
    3 ESHP
    4 Contractor
    5 NSI
    6 Base Staff

    can anybody help

  2. #2
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    When you set the multi-select to one of the settings which allows multiple values in a listbox, to get all the selected values from that listbox you'll need to write some vba code to walk through the items and see which ones are selected. You'll then need to figure out how you'll want to utilize the selected item values in the code. I'm pretty sure there are some listbox examples in the code repository.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Here's an example. The items selected are used to create a String Variable, with a Comma between each item. The String in this example is then assigned to a Control named MyTextBox for display, using

    Left(strNames, Len(strNames) - 1)

    to strip away the final Comma. Replace MyListBox and MyTextBox with the actual names of these Controls on your Form.
    Code:
    Private Sub MyListBox_AfterUpdate()
    
    Dim strNames As String
    
    Dim varItem As Variant
    
    For Each varItem In Me.MyListBox.ItemsSelected
      strNames = strNames & Me.MyListBox.ItemData(varItem) & ","
    Next varItem
    
    Me.MyTextBox = Left(strNames, Len(strNames) - 1)
    
    End Sub


    Linq ;0)>

  4. #4
    macaulayrg2003 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    6
    Hi Ling,

    Thank you for the help, but I am stll at a loss, I suspect I put this code into the after update in the events tab in the property box of my combo box. However I only have the one list with 6 departments on it so I don't understand why I would have 2 boxes named mylistbox and mytextbox. I am sorry if I am being dense with this

    Regards
    macaulayrg2003

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    You need to replace MyListBox, in the code, with the actual name of your Listbox, and MyTextBox with the actual name of the Textbox, on your Form, where you want to display these selections!

    Linq ;0)>

  6. #6
    macaulayrg2003 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2012
    Posts
    6
    Cheers Ling,

    Sorry about being a bit slow on the uptake. Got it to work now. I am trying to make a form with lots of Multi Value Fields, but it is driving me up the wall.

    Cheers
    macaulay

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Good luck with your project!

    Linq ;0)>

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Multiple Selection wth List Box / Combo Box
    By rkalapura in forum Forms
    Replies: 11
    Last Post: 02-09-2013, 11:02 PM
  2. how i make a query on combobox selction
    By eldarbs in forum Queries
    Replies: 16
    Last Post: 09-21-2012, 05:50 PM
  3. Replies: 23
    Last Post: 12-06-2011, 09:18 AM
  4. Replies: 2
    Last Post: 05-27-2011, 08:12 AM
  5. Loosing list box slection after refresh
    By oakoen in forum Forms
    Replies: 6
    Last Post: 11-23-2010, 11:21 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums