#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    USA
    Posts
    286
    Rep Power
    13

    Access Programming Question


    Howdy y'all,

    A friend of mine enlisted my help for programming a database she's using for her senior project. One little problem, though: it's an Access DB and I don't know VB, nor do I have the time to learn the ins and outs. I would appreciate a little code snippet/example of how to do the following:

    I have two combobox controls on a form: Combo1 and Combo2.

    Combo1 contains category information (e.g., Home, Garden, Tools, ...)
    Combo2 contains item information based on what is selected in Combo1.

    My question: How do you code the OnChange event for Combo1 to grab the selected value in Combo1, construct a SQL query to grab the necessary items, and then populate Combo2 with the new items?

    Thanks for any help,

    Comments on this post

    • JimmyGosling agrees
    Jon Sagara

    "Me fail English? That's unpossible!"
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Well, I haven't worked with VB in ages, and I'm not certain what method you're using to access the DB (I'm assuming ADODB in my example), but I hope this helps:
    Code:
        Dim sText As String
        Dim sSQL As String
        Dim rs as ADODB.Recordset
        sText = Combo1.Text
        
        sSQL = "SELECT foo FROM bar WHERE baz = " & sText
    
        ' Run your SQL statement here
        Combo2.Clear
        rs.Open sSQL
        While not rs.EOF       
           Combo2.AddItem (rs("FieldName"))
           rs.MoveNext
        Wend
        rs.Close
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    USA
    Posts
    286
    Rep Power
    13
    Thanks Scorpion.
    Jon Sagara

    "Me fail English? That's unpossible!"

IMN logo majestic logo threadwatch logo seochat tools logo