Variable Help

  • Thread starter Thread starter James
  • Start date Start date
J

James

I've got a value box (list box) where multiple choices can be selected.

I want to save those to a variable that I can use as a record set
filter. Here's some pseudo code:

values a, b,c


values a,b are selected
set variable x = records that have been selected


in a different module use this variable x as a filter (rs.Filter =
"OfferingID ='" & variable x & "'")


does that make since? I'm not really sure how to code it either...
Thanks for the help.
 
Ultimately the Filter string you are looking for will be something like
this:
"[MyField] IN ('a', 'b', 'c')"

For an example of how to build the string, see:
Use a multi-select list box to filter a report
at:
http://allenbrowne.com/ser-50.html
The code builds the string strWhere for a report, but you need exactly the
same string for the filter of your form.
 
Off the top of my head (untested) try this:

The ItemsSelected property of a ListBox is a Collection of the selected
items so you could populate a Collection globally Declared in a saved Module
as follows:
(Check that Collection Indexing starts at 1, it may start at 0, I can't
remember)

'In an appropriate Form level event:
Dim i As Integer
For i = 1 To Me.myListBox.ItemsSelected.Count
MyCollection(i) = Me.myListBox.ItemsSelected(i)
Next i

' In the saved module:
Public MyCollection As Collection

Then try iterating through MyCollection to build a String to use in the
Filter

Dim MyString As String

MyString = MyCollection(1) &'" OR '" & MyCollection(2).........

rs.Filter = "OfferingID ='" & MyString & "'"

Good Luck
 
thanks for the help, i got it to work and i did it using the
itemsselected property and some loops, thanks though
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top