Results 1 to 4 of 4

Thread: Need help w/ ComboBox validation code

  1. #1

    Thread Starter
    Addicted Member P.S.W.'s Avatar
    Join Date
    Aug 2000
    Posts
    146

    Unhappy

    I need a way, using an ordinary ComboBox (not Drop-Down List), to discard any typed-in entries that don't match up with an item on the list.

    For example, if someone types something in, then tabs out of the ComboBox, and whatever they typed in doesn't correspond to something already in the list, the ComboBox.Text will be reset to " " in the validation code.

    I'm sure this can't be too difficult but my brain is too tired. Can anyone help me?

  2. #2
    Lively Member Bios's Avatar
    Join Date
    Nov 1999
    Location
    Richton Park, IL, USA
    Posts
    71
    here this should work:

    Code:
    Sub Combo1_LostFocus()
    
    For a = 0 to Combo1.listcount-1
        if ucase(combo1.list(a))=ucase(combo1.text) then
            exit sub
        end if
        combo1.text=""
    Next a
    
    End Sub
    Hope this helps,
    Bios
    Age: 17
    Languages: (Q)BASIC, Visual Basic, Dark Basic,C/C++, Visual C++, Perl, Java Script, HTML, ASP

    "DO:BEEP:LOOP"

  3. #3
    New Member
    Join Date
    Jan 2001
    Posts
    13

    Exclamation Actually...

    There is a little bug in the previous code. it will not detect anything from the second item in the list down. If we make a slight change it works fine.

    Here is the modified code:

    Sub Combo1_LostFocus()

    For a = 0 to Combo1.listcount-1
    if ucase(combo1.list(a))=ucase(combo1.text) then
    exit sub
    end if
    Next a
    combo1.text=""


    End Sub

  4. #4

    Thread Starter
    Addicted Member P.S.W.'s Avatar
    Join Date
    Aug 2000
    Posts
    146

    Smile

    Thanks guys!

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