Results 1 to 12 of 12

Thread: [RESOLVED]Combo and SQL

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Resolved [RESOLVED]Combo and SQL

    Hi:

    I have a combo with a few items like:

    "Superman"
    "Spiderman"
    "catwoman"
    "BAtman"

    and I want,when I enter in the box,the letter "b",the combo shows the name batman for example....this is possible to do in VB?
    If yes ,can anybody put a few lines off code to do this?

    Thanks
    Last edited by sacramento; Dec 14th, 2004 at 07:30 AM.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Combo and SQL

    that is the default action of the combobox. doesn't it work?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Post Re: Combo and SQL

    Hi:

    sorry I don't now what you want mean about:

    "that is the default action of the combobox"

    Can you see a more expecific,please?

    Thanks

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Combo and SQL

    after you load it, if you click in the combobox, and type a letter, then the first item that starts with that letter is brought to the top, and selected.

  5. #5
    New Member
    Join Date
    Oct 2003
    Posts
    10

    Re: Combo and SQL

    no the default behaviour is not that, thats why i guess there are so many combox control for sale on the web.

    I just made that piece of code for you, it's not perfect but i'm sure you can improve it to suit your needs.

    Create a new form with a combobox, and paste that stuff in the code :

    Code:
    Option Explicit
    
    Private Sub Combo1_Change()
    
        Dim l_strLenght As Long
        Dim i As Long
        
        l_strLenght = Len(Combo1.Text)
        
        If l_strLenght = 0 Then Exit Sub
        
        For i = 0 To Combo1.ListCount - 1
            If StrComp(Combo1.Text, Left(Combo1.List(i), l_strLenght), vbTextCompare) = 0 Then
                Exit For
            End If
        Next i
    
        If i < Combo1.ListCount Then
            Combo1.ListIndex = i
            Combo1.SelStart = l_strLenght
            Combo1.SelLength = Len(Combo1.Text) - l_strLenght
        End If
    
    End Sub
    
    Private Sub Form_Load()
    
        Combo1.AddItem "Allo"
        Combo1.AddItem "Bllo"
        Combo1.AddItem "Cllo"
        Combo1.AddItem "Dllo"
        
        Combo1.ListIndex = 0
        
    End Sub
    What does it do ?
    Each time you modify the text of the combo it check the list to see if something starting like that exist, if yes, it select it. I also made it so it select the remaining of the text so you can keep typing.
    In your example if you type s, it would select spiderman, with "piderman" selected, so if you type a "u" after the "s" it'll select superman.
    Hard to explain, but easy to see, just try it.

    PS: i made that in 5 mins, dont shout at me if there are bugs in it

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Combo and SQL

    I put 0,8, ... 808 into a combo, and when I press 8, it get the cell for 8, if i press it again, i get 808, etc. if I type 80, it goes right to 808.

    It is a dropdown list. btw - selected item works right. I don't know whats wrong with mine. it's behaving oddly.
    Last edited by dglienna; Dec 13th, 2004 at 07:00 PM.

  7. #7
    New Member
    Join Date
    Oct 2003
    Posts
    10

    Re: Combo and SQL

    what ?

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Combo and SQL

    i used a new project, and made a combo, and loaded it with his data.
    when I set the style to 2 and ran it, it jumpled automatically.

  9. #9
    New Member
    Join Date
    Oct 2003
    Posts
    10

    Re: Combo and SQL

    It's just meant to be used with style = 0, that's just an example to get the poster started, not a full dumb proof solution.
    It can still be improved, example in my code you might wanna check if the last key pressed is the backspace, or you might see weird things

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Combo and SQL

    sorry, i was getting upset about why my combo wasn't working the way that it should. i knew that it was jumping to the right item with a keypress, though. there are 3 styles of combo, and they each act differently.

  11. #11
    Fanatic Member
    Join Date
    Sep 2004
    Location
    Jakarta, Indonesia
    Posts
    818

    Re: Combo and SQL

    maybe u wanna try combobox from Microsoft Form 2.0 Object Library and set it style property to frmStyledropDownList..

    it acts like the one u want

    regards

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL,
    Kill Database Processes

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: [RESOLVED]Combo and SQL

    Thanks to all

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