Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2005
    Posts
    46

    Unanswered: List Boxes Acces 2000

    Hi I have simple problem but can't find a fix for it.
    I have a text box which once the a button is clicked it adds the text to a listbox

    i.e

    Dim test As String
    test = Me.testbox.Value
    Me.listbox.AddItem test
    Simple hey

    How ever if the text has a comma, it then adds it as two items.
    So
    foo,bar
    becomes
    foo
    bar
    I've done some googeling and I got this answer
    Me.listbox.AddItem Chr(34) & test & Chr(34)

    But this then breaks the code if a double quote is used in the text
    ie
    foo"bar"
    becomes
    foo
    Any help greatly appreciated I think I might need to use the instr function to replace the commas with something

  2. #2
    Join Date
    Nov 2007
    Posts
    93

    list box

    Private Sub Form_form2()
    Dim oItem As Variant
    Dim bFound As Boolean
    Dim sTemp As String
    Dim sValue As String
    Dim sChar As String
    Dim iCount As Integer
    Dim iListItemsCount As Integer

    sTemp = Nz(Me!mySelections.Value, " ")
    iListItemsCount = 0
    bFound = False
    iCount = 0


    For iCount = 1 To Len(sTemp) + 1
    sChar = Mid(sTemp, iCount, 1)
    If StrComp(sChar, ",") = 0 Or iCount = Len(sTemp) + 1 Then
    bFound = False
    Do
    If StrComp(Trim(Me!NamesList.ItemData(iListItemsCount )), Trim(sValue)) = 0 Then
    Me!NamesList.Selected(iListItemsCount) = True
    bFound = True
    End If
    iListItemsCount = iListItemsCount + 1
    Loop Until bFound = True Or iListItemsCount = Me!NamesList.ListCount
    sValue = ""
    Else
    sValue = sValue & sChar
    End If
    Next iCount
    End Sub


    hope this helpful

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Whenever I see these questions about using AddItem to add data to a combobox or listbox, I feel I have to ask if you understand that these added items will be gone, the next time you open the form.

    Sometimes it matters and sometimes it doesn't, but only items added in Design View are added permanently.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •