473,385 Members | 1,396 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.

Multi-Select Listbox: Loop through, ignoring duplicate items

pcb
Hi All,

I have a multi-select listbox, that can have duplicate items (i.e
samples numbers that are analyzed in duplicate - the sample IDs are not
the same, but these IDs are hidden from the user).

I want to loop through the items on the listbox, but only use unique
sample numbers. Here is what I have:
************************************************** ***********************
Dim varItem As Variant
Dim frm As Form, ctl As Control
Dim strSampleList As String

Set frm = Forms!frmUpdateSamples
Set ctl = frm!lboSamples

For Each varItem In ctl.ItemsSelected
If ** ??? not duplicate ??? ** Then
strSampleList = strSampleList & ctl.Column(1, varItem) & vbCrLf
End If
Next varItem

************************************************** ***********************

Any help would be great. Thanks!
Peter

Nov 13 '05 #1
1 4220
Hi Peter,

My solution isn't super pretty, but it works. I am using a temp table
as follows:

Sub GetUniqueVals()
Dim varItem As Variant
Dim strSampleList As String
Dim RS As DAO.Recordset, obj As AccessObject

DoCmd.SetWarnings False
For Each obj In CurrentData.AllTables
If obj.Name = "Temp1" Then
DoCmd.RunSQL "Drop Table Temp1" '--delete table first
Exit For
End If
Next
DoCmd.RunSQL "Create Table Temp1 (fld1 Text(20))"
For Each varItem In List0.ItemsSelected
DoCmd.RunSQL "Insert Into Temp1(fld1) Values('" & List0.Column(1,
varItem) & "')"
Next

Set RS = CurrentDb.OpenRecordset("SELECT fld1 FROM Temp1 GROUP BY fld1")
Do While Not RS.EOF
strSampleTest = strSampleTest & RS(0) & ", "
RS.MoveNext
Loop
DoCmd.SetWarnings True
Debug.print strSampleTest
End Sub

HTH

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #2

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

Similar topics

37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
4
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
0
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
6
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
5
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone...
17
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.