multiselect list box

michaelk

New member
Local time
Today, 21:45
Joined
Sep 25, 2001
Messages
7
I do not know much VBA code. All I know I have learned from this website J Hopefully you can help me with this problem.

I have a multi-select list box with three columns. The third column is [ID] (This is the bound column)

I need code to create a string that looks like “[ID] = 2 or [ID] = 3 or [ID] =355” and so on based on the selections I make.

This string will become the filter criteria for a report using code that I already have.

Since this applies to code as well as a form function I'm going to place this same post in the Code forum as well.

Thanks again for all any help you can give me, as well as for all the help I've recieved in the past here.
 
Any time you want to refer to the value of the bound column of a list box (or combo box) you need only use the name of the control.
For example, if you were building the SQL string using the value of your list box it might look like...

strSQL = "SELECT * from tblTest WHERE ID = " & me.lstNameOfListBox & ";"

Or you might base the Report on a Query built within the QBE. In this case you might put a Criteria in the design of the Query that looked like

= Forms!frmTest!lstNameOfListBox

Or you might use the OpenReport method of the DoCmd object. In a form event you would go...

dim rpt_crit as string

rpt_crit = "ID = " & me.lstListBoxName

HTH
Chris
 
To identify all the options you have selected in a multi-select listbox you can do the following:

for i = 0 to Me!Listbox.Listcount - 1
if Me!Listbox.Selected(i) then
... 'Enter code here
end if
next i

Just replace Listbox with the name of your listbox.

I hope this is what you're after.

Cheers,
SteveA
 

Users who are viewing this thread

Back
Top Bottom