Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 09-28-2015, 01:49 AM   #1
kurto55
Newly Registered User
 
Join Date: Sep 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
kurto55 is on a distinguished road
Help needed in looping through a multi-select listbox

Hi all -

I have (hopefully) a simple problem that I need help with. I have a simple form that has a multi-select list box that is populated by another table. The list box shows one value (the 3rd column), but the table has 3 columns (the first two are not shown. When the user clicks the button, I want to populate a new record with each of the three variables. The number of grantees selected shows the right number, but I seem to be having trouble moving through the selected records. Here is my code so far, but this only shows the values of the last selected item over and over. I seem to be having trouble looping though the selected items.

Private Sub Command4_Click()

If Me.List2.ItemsSelected.Count = 0 Then
MsgBox "No grantee has been selected - please try again"
Else

MsgBox "Number of grantees selected: " & Me.List2.ItemsSelected.Count

Dim x As Variant

For Each x In Me.List2.ItemsSelected

MsgBox Me.List2.Column(0)
MsgBox Me.List2.Column(1)
MsgBox Me.List2.Column(2)

Next

End If
End Sub



Any help would be much appreciated!

kurto55 is offline   Reply With Quote
Old 09-28-2015, 03:23 AM   #2
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,568
Thanks: 68
Thanked 2,744 Times in 2,629 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Help needed in looping through a multi-select listbox

Private Sub Command4_Click()

If Me.List2.ItemsSelected.Count = 0 Then
MsgBox "No grantee has been selected - please try again"
Else

MsgBox "Number of grantees selected: " & Me.List2.ItemsSelected.Count

Dim x As Variant
Dim strSelected as String

For Each x In Me.List2.ItemsSelected

strSelected = strSelected & Me.List2.Column(x,0) & " " & _
Me.List2.Column(x, 1) & " " & _
Me.List2.Column(x, 2) & vbCrLf

Next
MsgBox strSelected
End If

End Sub
arnelgp is offline   Reply With Quote
Reply

Tags
box , form , list , listbox , loop

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Dynamic row source for listbox from multi-select listbox sk84gtspd Forms 5 06-10-2015 02:57 PM
Multi-select listbox. Henley12 Forms 15 03-26-2010 08:06 AM
select values in multi select listbox nitsua Forms 1 08-20-2005 01:40 PM
Multi Select Listbox database Forms 16 07-13-2004 08:26 AM
yet another Multi-select Listbox ?? wannabe Forms 8 03-22-2003 09:11 PM




All times are GMT -8. The time now is 03:38 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World