multi-selection list boxes - help!

jayk

New member
Local time
Today, 17:05
Joined
Dec 19, 2000
Messages
8
I have three list boxes in one form. I need to multi-select from each list box and then run a query to find all the database entries which fall under my choices. How do i create multi-selection list boxes and what command should i use to run the query??
Also, what command should i use to then put the queried data into a standard access datasheet allwoing me to use it as part of a mail-merge?
 
There is a multi-select property for the ListBox control. Make sure Properties is selected under the View menu. Play with that.

For your query, you must build your criteria string. (Your WHERE clause) I assume since you have 3 list boxes, you have three fields that need to be queried on.

Public Sub DoIt_Click()
Dim First, Secnd, Thrd, Sql_Str as String
dim varItm as Variant
dim dbs as Database

set dbs = CurrentDb

First = "("
For Each varItm In List1.ItemsSelected
First = First & Me.List1.ItemData(varItm) & ", "
Next varItm
First = Left(First, Len(First) - 1) & ")"

Secnd= "("
For Each varItm In List2.ItemsSelected
Secnd = Secnd & Me.List2.ItemData(varItm) & ", "
Next varItm
Secnd = Left(Secnd, Len(Secnd) - 2) & ")"

Thrd= "("
For Each varItm In List3.ItemsSelected
Thrd= Thrd & Me.List3.ItemData(varItm) & ", "
Next varItm
Thrd = Left(Thrd, Len(Thrd) - 2) & ")"

Sql_Str = "SELECT * INTO Tbl_MergeTemp FROM Tbl_YourTable WHERE Field1 IN " & First & " AND Field2 IN " & Secnd & " AND Field3 IN " & Thrd

dbs.execute (Sql_Str)

end sub

You will now have a table out there (Tbl_MergeTemp) to run your mail merge off of.

[This message has been edited by pdx_man (edited 02-27-2001).]
 
I have sent a small Access97 demo to your email address.
 

Users who are viewing this thread

Back
Top Bottom