ItemsSelected Seems not to work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KC-Mass

    #1

    ItemsSelected Seems not to work

    I am working with a multi select list box in access. The code is:

    Sub MoveToCustomer2 ()
    Dim frm As Form, Ctl As Control
    Dim varItem As Variant
    Set frm = Forms!frmResolv eCustomers
    Set Ctl = frm!lstUnassign ed
    For Each varItem In Ctl.ItemsSelect ed
    Debug.Print varItem
    Debug.Print Ctl.Column(0)
    Next varItem
    End Sub

    If I select items 2, 3, 6and 8 the program prints 1,2,5,7 which is correct
    (zero based)but for
    ctl.Column(0) it prints the value of the first selectedItems for each of the
    4 selected records.

    They should all be different.

    Is the reference to the column wrong?


    Thx

    Kevin


  • Salad

    #2
    Re: ItemsSelected Seems not to work

    KC-Mass wrote:
    I am working with a multi select list box in access. The code is:
    >
    Sub MoveToCustomer2 ()
    Dim frm As Form, Ctl As Control
    Dim varItem As Variant
    Set frm = Forms!frmResolv eCustomers
    Set Ctl = frm!lstUnassign ed
    For Each varItem In Ctl.ItemsSelect ed
    Debug.Print varItem
    Debug.Print Ctl.Column(0)
    Next varItem
    End Sub
    >
    If I select items 2, 3, 6and 8 the program prints 1,2,5,7 which is correct
    (zero based)but for
    ctl.Column(0) it prints the value of the first selectedItems for each of the
    4 selected records.
    >
    They should all be different.
    >
    Is the reference to the column wrong?
    >
    Yes.

    'this returns the index
    Private Sub Command1_Click( )
    Dim var As Variant
    For Each var In Me.List0.ItemsS elected
    MsgBox var
    Next
    End Sub

    'this returns the values using the index. You can
    'also use ItemData as well to get the value per online help.
    Private Sub Command2_Click( )
    Dim var As Variant
    For Each var In Me.List0.ItemsS elected
    MsgBox Me.List0.Column (0, var) & " " & Me.List0.Column (1, var)
    Next
    End Sub

    'this returns the values using a counter
    Private Sub Command3_Click( )
    Dim intFor As Integer
    For intFor = 0 To Me.List0.ListCo unt - 1
    If Me.List0.Select ed(intFor) Then
    MsgBox Me.List0.Column (0, intFor) & " " &
    Me.List0.Column (1, intFor)
    End If
    Next

    End Sub

    Garden Party

    >
    Thx
    >
    Kevin
    >
    >

    Comment

    • KC-Mass

      #3
      Re: ItemsSelected Seems not to work

      Thanks Much!

      Kevin

      "Salad" <oil@vinegar.co mwrote in message
      news:OPSdnRvmCf _04oHVnZ2dnUVZ_ j6dnZ2d@earthli nk.com...
      KC-Mass wrote:
      >I am working with a multi select list box in access. The code is:
      >>
      >Sub MoveToCustomer2 ()
      > Dim frm As Form, Ctl As Control
      > Dim varItem As Variant
      > Set frm = Forms!frmResolv eCustomers
      > Set Ctl = frm!lstUnassign ed
      > For Each varItem In Ctl.ItemsSelect ed
      > Debug.Print varItem
      > Debug.Print Ctl.Column(0)
      > Next varItem
      >End Sub
      >>
      >If I select items 2, 3, 6and 8 the program prints 1,2,5,7 which is
      >correct (zero based)but for
      >ctl.Column(0 ) it prints the value of the first selectedItems for each of
      >the 4 selected records.
      >>
      >They should all be different.
      >>
      >Is the reference to the column wrong?
      >>
      Yes.
      >
      'this returns the index
      Private Sub Command1_Click( )
      Dim var As Variant
      For Each var In Me.List0.ItemsS elected
      MsgBox var
      Next
      End Sub
      >
      'this returns the values using the index. You can
      'also use ItemData as well to get the value per online help.
      Private Sub Command2_Click( )
      Dim var As Variant
      For Each var In Me.List0.ItemsS elected
      MsgBox Me.List0.Column (0, var) & " " & Me.List0.Column (1, var)
      Next
      End Sub
      >
      'this returns the values using a counter
      Private Sub Command3_Click( )
      Dim intFor As Integer
      For intFor = 0 To Me.List0.ListCo unt - 1
      If Me.List0.Select ed(intFor) Then
      MsgBox Me.List0.Column (0, intFor) & " " & Me.List0.Column (1,
      intFor)
      End If
      Next
      >
      End Sub
      >
      Garden Party

      >
      >>
      >Thx
      >>
      >Kevin

      Comment

      Working...