473,385 Members | 2,180 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,385 software developers and data experts.

Determining Position In ItemsSelected Collection

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 list box, the item is added to
a string, and that string becomes part of the WHERE clause. I need to
identify the first item chosen, since the string that it is put into is
slightly different than for the subsequent items. The problem I'm having is
figuring what to look at that tells me it is the first one.

I'm using the ItemsSelected collection, and my code I'm using to start out
is:

Dim frm As Form, ctl As Control
Dim varItm As Variant

Set frm = Forms!frmGCSBanksNotSurveyedReport
Set ctl = frm!lstHost
For Each varItm In ctl.ItemsSelected
Debug.Print "varItm = " & varItm
Next varItm

What happens is that for some reason varItm seems to be the index of the
chosen item in the original list box, not its index in the ItemsSelected
collection. What can I look at to determine the position of the item in the
ItemsSelected collection instead of the original list?

Thanks.

Steve
Nov 12 '05 #1
1 2879
how about something like this:

Private Sub Command2_Click()
'Const cDELIMITER As String = "#" 'Date
'Const cDELIMITER As String = "'" 'Text
'Const cDELIMITER As String = "" 'Numeric

Dim lbx As ListBox
Dim varItem As Variant
Dim strList As String

Set lbx = Me.List0
For Each varItem In lbx.ItemsSelected
strList = strList & ", " & cDELIMITER & lbx.ItemData(varItem)
& cDELIMITER
Next varItem
strList = Right$(strList, Len(strList) - 2)
MsgBox strList
End Sub

I would create a function or something to return the selected items in
the listbox and then just include the function as the criteria for my
query or something. Just make sure to delimit your values. You'd
just have to wrap the individual values in the proper delimiter... Or
you could just modify the SQL syntax on the fly... whatever. THere's
a good example of playing with listboxes on www.mvps.org/access in the
forms section.... Happy reading.
Nov 12 '05 #2

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

Similar topics

0
by: D & J Gilchrist | last post by:
Hi Is there any way of determining the width and height of a graphic in pixels (.jpg) and reporting this? Also, maybe following the above, can a picture-box position be automatically moved to...
3
by: CES | last post by:
All, Is their a way of finding the position of the browsers top-left-hand-corner as it relates to the monitors screen resolution?? By that I mean that if the browser's window is at the upper most...
2
by: Ney André de Mello Zunino | last post by:
Hello. To find the position of an element within a collection, I currently follow these two steps: 1. obtain an iterator to the element (i.e. find it) 2. use std::distance with coll.begin()...
7
by: todholt | last post by:
Hello, I am trying to bypass a form's automatic update, and instead call a stored procedure in sql server. I am using continuous forms. The problem I am having is with returning to the next...
6
by: Alex | last post by:
I have been loving the templated datacolumns of the datagrid. I have stumbled onto a problem though that is beyond by knowledge and I was hoping someone here could jumpstart me. My templated...
2
by: JohnR | last post by:
Sorry if this is has an obvious answer, but I can't find it... I am using a datatable.select to obtain the rows in a datatable that meet certain criteria. My question is this: for each of the...
2
by: KC-Mass | last post by:
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 =...
8
by: secutos | last post by:
Programming Language: C#, .NET Framework 3.5 In this context, Form and App both describe a Microsoft Windows desktop application i'm creating. I'm creating a wordlist generator. I need to be able...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.