473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

ItemsSelected Seems not to work

I am working with a multi select list box in access. The code is:

Sub MoveToCustomer2()
Dim frm As Form, Ctl As Control
Dim varItem As Variant
Set frm = Forms!frmResolveCustomers
Set Ctl = frm!lstUnassigned
For Each varItem In Ctl.ItemsSelected
Debug.Print varItem
Debug.Print Ctl.Column(0)
Next varItem
End Sub

If I select items 2, 3, 6and 8 the program prints 1,2,5,7 which is correct
(zero based)but for
ctl.Column(0) it prints the value of the first selectedItems for each of the
4 selected records.

They should all be different.

Is the reference to the column wrong?
Thx

Kevin
Jun 27 '08 #1
2 4851
KC-Mass wrote:
I am working with a multi select list box in access. The code is:

Sub MoveToCustomer2()
Dim frm As Form, Ctl As Control
Dim varItem As Variant
Set frm = Forms!frmResolveCustomers
Set Ctl = frm!lstUnassigned
For Each varItem In Ctl.ItemsSelected
Debug.Print varItem
Debug.Print Ctl.Column(0)
Next varItem
End Sub

If I select items 2, 3, 6and 8 the program prints 1,2,5,7 which is correct
(zero based)but for
ctl.Column(0) it prints the value of the first selectedItems for each of the
4 selected records.

They should all be different.

Is the reference to the column wrong?
Yes.

'this returns the index
Private Sub Command1_Click()
Dim var As Variant
For Each var In Me.List0.ItemsSelected
MsgBox var
Next
End Sub

'this returns the values using the index. You can
'also use ItemData as well to get the value per online help.
Private Sub Command2_Click()
Dim var As Variant
For Each var In Me.List0.ItemsSelected
MsgBox Me.List0.Column(0, var) & " " & Me.List0.Column(1, var)
Next
End Sub

'this returns the values using a counter
Private Sub Command3_Click()
Dim intFor As Integer
For intFor = 0 To Me.List0.ListCount - 1
If Me.List0.Selected(intFor) Then
MsgBox Me.List0.Column(0, intFor) & " " &
Me.List0.Column(1, intFor)
End If
Next

End Sub

Garden Party
http://www.youtube.com/watch?v=O_exY9ptMbA
>
Thx

Kevin

Jun 27 '08 #2
Thanks Much!

Kevin

"Salad" <oi*@vinegar.comwrote in message
news:OP******************************@earthlink.co m...
KC-Mass wrote:
>I am working with a multi select list box in access. The code is:

Sub MoveToCustomer2()
Dim frm As Form, Ctl As Control
Dim varItem As Variant
Set frm = Forms!frmResolveCustomers
Set Ctl = frm!lstUnassigned
For Each varItem In Ctl.ItemsSelected
Debug.Print varItem
Debug.Print Ctl.Column(0)
Next varItem
End Sub

If I select items 2, 3, 6and 8 the program prints 1,2,5,7 which is
correct (zero based)but for
ctl.Column(0) it prints the value of the first selectedItems for each of
the 4 selected records.

They should all be different.

Is the reference to the column wrong?
Yes.

'this returns the index
Private Sub Command1_Click()
Dim var As Variant
For Each var In Me.List0.ItemsSelected
MsgBox var
Next
End Sub

'this returns the values using the index. You can
'also use ItemData as well to get the value per online help.
Private Sub Command2_Click()
Dim var As Variant
For Each var In Me.List0.ItemsSelected
MsgBox Me.List0.Column(0, var) & " " & Me.List0.Column(1, var)
Next
End Sub

'this returns the values using a counter
Private Sub Command3_Click()
Dim intFor As Integer
For intFor = 0 To Me.List0.ListCount - 1
If Me.List0.Selected(intFor) Then
MsgBox Me.List0.Column(0, intFor) & " " & Me.List0.Column(1,
intFor)
End If
Next

End Sub

Garden Party
http://www.youtube.com/watch?v=O_exY9ptMbA
>>
Thx

Kevin

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steve Edwards | last post by:
I have a form with a list box, and the items selected from that list box are used to add values to the WHERE clause of a query that is the data source for a report. For each item chosen from the...
1
by: | last post by:
I am having trouble getting the procedure to use a Multiselect listbox in a report to work. I am using Access 2000. Here's the code. The error I get is QueryDef "User-defined type not...
5
by: teddysnips | last post by:
I have to write an application to do some data cleansing. It's a Contact database, but over a number of years there are multiple companies which are all essentially the same entity. For each...
6
by: Max | last post by:
Hello - Just switched to PHP 5 and just realized that all my scripts with relative paths for require statements no longer work unless I put the absolute path. Usually, if the file is in the same...
13
by: Wayne | last post by:
I have just experienced my first late paying client. By "late" I mean that the invoice is now almost 2 months overdue. I don't think that the client is maliciously withholding payment - rather...
0
by: titojermaine | last post by:
The problem is that after reducing MSDTC security to "No Authentication", it mostly seems to work correctly, except that after a brief period of inactivity (a few minutes), the first attempt to use...
2
by: Proaccesspro | last post by:
I have this code in a list box. I'm trying to determine which PrintButton to display based upon the users selection. When executed I get this error "Argument not optional" Any ideas? Also, the...
16
by: DavidGeorge | last post by:
I have an unbound form with three list boxes. The selections made in these list boxes 'filter' the records that appear in an unbound subform. The subform record source is a query which looks at...
2
sassy2009
by: sassy2009 | last post by:
Hello All, I have got a listbox which lists the files from a network folder. I have set the multiselect property to Extended. What iam trying to do now is display the multiple file names from the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.