Results 1 to 3 of 3

Thread: sql question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Posts
    125
    Data1 and Data2 Controls both have the same Databasename

    there are two tables in the database

    one table named categories has
    CategoryNames and CategoryID fields

    the other table named Products has
    ProductNames and CategoryID fields


    Data1.RecordSource is set to Categories
    Data2.RecordSource is not set

    DBCombo1.Rowsource = Data1
    DBCombo1.Listfield = CategoryNames

    DBList1.Rowsource = Data2
    DBList1.Listfield = ProductNames

    ====================================================

    Programatically I want to set the Data2.RecordSource
    when I choose an item in the BDcombo to populate the
    DBlist

    ====================================================

    Now if the DBCombo1.Listfield = CategoryID the code
    is simple as follows:


    Private Sub DBCombo1_Change()

    Data2.RecordSource = "SELECT DISTINCTROW _
    Products.ProductName FROM Products WHERE _
    (Products.CategoryID = " & DBCombo1.Text & ");"

    Data2.Refresh

    End Sub

    ====================================================

    But what is the code since
    DBCombo1.Listfield = CategoryNames ?

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83
    I am not sure that I understand your question. But I will give you an answer so at least your thread pops to the top.

    Data2.RecordSource = "SELECT DISTINCTROW _
    Products.ProductName FROM Products, categories WHERE _
    (Products.CategoryID = categories.CategoryID ) AND _ categories.ProductNames = DBCombo1.Text );"

    I JOIN the two tables over CategoryID. You cold also put the CategoryID as a part of the sting in the combobox and exctract it from the DBCombo1.Text.


    Yesterday, all my troubles seemed so far away...
    Help, I need somebody, Help...
    Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Posts
    125
    thanks I have it working now

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