listbox- how to get first item only

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Bailey

    listbox- how to get first item only

    I have a list box where the user might need to select two items which builds
    up an sql string. Another part of the function only requires the first item.

    here is the code :
    For Each varItems In Me.ListDOS.Item sSelected

    If strMods = vbNullString Then
    strMods = "=" & """" & Me.ListDOS.Colu mn(1, varItems) & """"
    Else
    strMods = "=" & """" & Me.ListDOS.Colu mn(1, varItems) & """"
    End If
    Next varItems

    I am not sure how to amend it so that it reaches only the first item, stores
    it to strMods and then drops out of the loop.

    regards in advance.

    Peter


  • MGFoster

    #2
    Re: listbox- how to get first item only

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    ' this is a very easy solution
    ' probably a much more elegant one, that I can't think of

    For Each varItems In Me.ListDOS.Item sSelected
    If strMods = vbNullString Then
    strMods = "=" & """" & Me.ListDOS.Colu mn(1, varItems) & """"
    Else
    strMods = "=" & """" & Me.ListDOS.Colu mn(1, varItems) & """"
    End If

    exit for

    Next varItems

    --
    MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
    Oakland, CA (USA)

    -----BEGIN PGP SIGNATURE-----
    Version: PGP for Personal Privacy 5.0
    Charset: noconv

    iQA/AwUBQUcyjIechKq OuFEgEQL6cQCeOL dsBH9G+0KlV0bKY m+DxzXNHvcAoMXX
    EOWcSgKVvpX4nBX h9slLg+0x
    =MOof
    -----END PGP SIGNATURE-----


    Peter Bailey wrote:
    [color=blue]
    > I have a list box where the user might need to select two items which builds
    > up an sql string. Another part of the function only requires the first item.
    >
    > here is the code :
    > For Each varItems In Me.ListDOS.Item sSelected
    >
    > If strMods = vbNullString Then
    > strMods = "=" & """" & Me.ListDOS.Colu mn(1, varItems) & """"
    > Else
    > strMods = "=" & """" & Me.ListDOS.Colu mn(1, varItems) & """"
    > End If
    > Next varItems
    >
    > I am not sure how to amend it so that it reaches only the first item, stores
    > it to strMods and then drops out of the loop.[/color]

    Comment

    Working...