Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Variable Help

Discussion in 'Information Technology' started by James, Jul 28, 2006.

Tags:
  1. James

    James
    Expand Collapse
    Guest

    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.
     
  2. Loading...


  3. Allen Browne

    Allen Browne
    Expand Collapse
    Guest

    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.

    --
    Allen Browne - Microsoft MVP. Perth, Western Australia.
    Tips for Access users - http://allenbrowne.com/tips.html
    Reply to group, rather than allenbrowne at mvps dot org.

    "James" <jamesburkett@gmail.com> wrote in message
    news:1151070451.987167.64760@r2g2000cwb.googlegroups.com...
    > 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.
     
  4. Jon Lewis

    Jon Lewis
    Expand Collapse
    Guest

    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

    "James" <jamesburkett@gmail.com> wrote in message
    news:1151070451.987167.64760@r2g2000cwb.googlegroups.com...
    > 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.
    >
     
  5. James

    James
    Expand Collapse
    Guest

    thanks for the help, i got it to work and i did it using the
    itemsselected property and some loops, thanks though
    Jon Lewis wrote:
    > 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
    >
    > "James" <jamesburkett@gmail.com> wrote in message
    > news:1151070451.987167.64760@r2g2000cwb.googlegroups.com...
    > > 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.
    > >
     

Share This Page