Results 1 to 4 of 4

Thread: List Boxes

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    2

    Question

    Hello All,


    I am new to Visual Basic. I am perform error checking for list boxes. How do I check for a value that is already in the list box. Example Message Box: "You have already select this value" The value is already listed in the list box. Thanks, for your help.

  2. #2
    Guest
    you can loop through the list items to check for duplicates. Add the following to a Form with a ListBox, TextBox and CommandButton.
    Code:
    Function CheckListBox(lst As ListBox, sString As String) As Boolean
        CheckListBox = True
        For I = 0 To lst.ListCount
            If lst.List(I) = sString Then CheckListBox = False
        Next I
    End Function
    
    Private Sub Command1_Click()
        If CheckListBox(List1, Text1) Then List1.AddItem Text1
    End Sub
    Enter something in the TextBox and press the Button. If it's not a duplicate, then it will be added else it will not be added.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    2

    Smile

    Thanks, Megatron

    Do you (or anybody else) know of a way to check for duplicate values in a listbox without using a command button? My program is design whereas a user double-click on a calendar and the date is put in a listbox. The error checking should occur if the user select that same date twice. I am working with an Access 97 database.

    Thanks again!!

  4. #4
    Lively Member Jamagei's Avatar
    Join Date
    Jul 2000
    Location
    running from you. You freak.
    Posts
    69
    just put the command1_click event under the dblclick event of the calander control. then everytime you double click on the calender the function fires.
    Now, aren't you sorry you didn't just keep on scrolling?

Posting Permissions

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



Click Here to Expand Forum to Full Width