Results 1 to 9 of 9

Thread: Validate combobox - manual type

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2020
    Posts
    31

    Smile Validate combobox - manual type

    Hello,

    I'm working on an old projet. I created a Combobox with a list of value from a variable source (SQL), so I can't hard coded the values for validation.

    I use this code to grab the 1st value in the list without having to use the mouse to select.

    Code:
    Private Sub ComboTypeAppel_Change()
        
        Dim i As Long
        Dim lngText As Long
        'If firing in response to a backspace or delete, don't run the auto-complete
        'complete code. (Otherwise you wouldn't be able to back up.)
        If blnBackSpace = True Or ComboTypeAppel.Text = vbNullString Then
            blnBackSpace = False
            Exit Sub
        End If
        
        'Run through the available items and grab the first matching one.
        For i = 0 To ComboTypeAppel.ListCount - 1
            If InStr(1, ComboTypeAppel.List(i), ComboTypeAppel.Text, vbTextCompare) = 1 Then
                'Save the SelStart property.
                lngText = ComboTypeAppel.SelStart
                ComboTypeAppel.Text = ComboTypeAppel.List(i)
                'Set the selection in the combo.
                ComboTypeAppel.SelStart = lngText
                ComboTypeAppel.SelLength = Len(ComboTypeAppel.Text) - lngText
                Exit For
            End If
        Next
    End Sub
    When I validate, the combobox.listindex will return the right value when I use the mouse-click but will always return -1 when I type in.

    How can I validate that the value of the combobox is part of the valut list ?

    Please provide code, I'm a newbie working on some else old code.

    Thanks

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    8,899

    Re: Validate combobox - manual type

    Hard to understand your desire...but have you looked at keyDown, keyPress and keyUP of the combobox?

    PROBABLY at keyUP you may be able to do your validation (whatever that is).
    Sam I am (as well as Confused at times).

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2020
    Posts
    31

    Re: Validate combobox - manual type

    My desire is to validate a combobox that what ever the user enter MUST be part of the value list I created... he cannot enter any other value.

    BUT since I want to allow a fast manual key punch to go the precise item on the list (type M will bring the list the the 1st M item, but if you type "MA" the combo jump to 1st M, then 1st A, I want it to go to the 1st "MA" item. That is why I use the "select as you type" on the combo_change Sub

    The combobox STYLE is set to 0- Dropdown Combo

    I think I will work somethink like this

    Code:
    For i = 0 To ComboTech.ListCount - 1
        If ComboTech = ComboTech.List(i) Then
            Exit Sub
            Else
     'deal with error
            Exit Sub
        End If
    Next

  4. #4
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,797

    Re: Validate combobox - manual type

    https://learn.microsoft.com/en-us/do...owsdesktop-8.0

    Use the AutoCompleteCustomSource, AutoCompleteMode, and AutoCompleteSource properties to create a ComboBox that automatically completes input strings by comparing the prefix being entered to the prefixes of all strings in a maintained source. This is useful for ComboBox controls in which URLs, addresses, file names, or commands will be frequently entered. If there are duplicate entries in the maintained source, automatic completion behaves unpredictably.
    Please remember next time...elections matter!

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2020
    Posts
    31

    Re: Validate combobox - manual type

    is this is for VB6 or .Net

  6. #6
    Member
    Join Date
    Nov 2023
    Posts
    44

    Re: Validate combobox - manual type

    I think it should be an easy task. But there will be no AutoCompleteCustomSource in VB6

  7. #7
    Member
    Join Date
    Nov 2023
    Posts
    44

    Re: Validate combobox - manual type

    https://www.vbforums.com/showthread....box-with-entry

    By the way, I found the answer to your question, back in 2005 they wrote about it on the forum

    But I want to note right away that the code that is given there, although it works, but only for Latin letters, and this will be inconvenient for people from other countries of the world where the Latin alphabet is not used
    Last edited by HackerVlad; Nov 22nd, 2023 at 06:58 AM.

  8. #8
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    8,899

    Re: Validate combobox - manual type

    Need a little more guidance, if you please. USUALLY, a ComboBox is used for SELECTING items, not ENTERING new ones. Similar to ListBoxes. Textboxes are NORMALLY used for this sort of thing (checking against other items in other controls/databases/etc). What is the end purpose of the ComboBox? Is it to end up with a new 'list' if things that may be found in another listbox (valut list?)?
    Sam I am (as well as Confused at times).

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Apr 2020
    Posts
    31

    Re: Validate combobox - manual type

    I understand, I always use the combobox to force user to use only value list.

    Sorry if my explaination are not clear, english is not my main language.

    When you want your task force to work fast on data entry, you must create a GUI that make it easy to get it done with minimal use of the mouse. In my case it's for invoicing.

    That is why I want to validate the value enter is part of the value list. As I explained combobox will jump to the 1st letter, but if in the list you have 30 choices that start with that Letter, you will have to 1st type the letter end then scroll with the arrow all the way to your value... time consuming !! While using select as you type, will allow the user to type 2-3 letters and will go the the right item.

    So since VB6 will return -1 in that case and not the proper valuelist item number... I did manage to do it using FOR - NEXT statement that loop thru all the values and compare if it match or not.

    And now it work perfectcly, just as I needed it.

    Thanks everyone.
    Last edited by jffortier; Nov 22nd, 2023 at 06:40 PM.

Tags for this Thread

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