Multiselect list problem

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I am using the following get the items from a multiselect list;

Dim ctl As Control
For Each ctl In Me.BatchInvoicesList.ItemsSelected

Problem is that I am getting a 'Object not found error'. Same with;

For Each ctl In Me!BatchInvoicesList.ItemsSelected

What am I doing wrong?

Thanks
 
The ItemsSelected collection doesn't return a control. It's a collection of
Variants, where each Variant is an integer index referring to a selected row
in the list box. Try:

Dim ctl As Variant

For Each ctl In Me.BatchInvoicesList.ItemsSelected
 
ItemsSelected is a collection of Variants!

From the Help file ----
Sub BoundData()
Dim frm As Form, ctl As Control
Dim varItm As Variant

Set frm = Forms!Contacts
Set ctl = frm!Names
For Each varItm In ctl.ItemsSelected
Debug.Print ctl.ItemData(varItm)
Next varItm
End Sub

The next example uses the same list box control, but prints the values of
each column for each selected row in the list box, instead of only the
values in the bound column.

Sub AllSelectedData()
Dim frm As Form, ctl As Control
Dim varItm As Variant, intI As Integer

Set frm = Forms!Contacts
Set ctl = frm!Names
For Each varItm In ctl.ItemsSelected
For intI = 0 To ctl.ColumnCount - 1
Debug.Print ctl.Column(intI, varItm)
Next intI
Debug.Print
Next varItm
End Sub
 
--
To anyone that reads this message thread, you should be aware that PC
Datasheet is notorious for advertising in newsgroups that are intended for
the *free* exchange of Access help. There are numerous consultants that
provide free expert support here. Datasheet has been repeatedly asked to
stop, but refuses.

If you would like to know more about this individual, please use the link
below.

http://home.tiscali.nl/arracom/whoissteve.html

Randy Harris
 
Back
Top