Results 1 to 6 of 6

Thread: Lenin - Data Environment

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Hello Lenin! I saw you helping Lentro the other day and might see if you can help me on the similar subject.


    Using Data Environment!

    If I have two DataComboxes, how can I make it so that picking the first datacombo box will give me corresponding choices in the second datacombo box. Can you give me a step by step instruction because I have been stump on this.

    Thank You in Advance.
    Chemically Formulated As:
    Dr. Nitro

  2. #2
    Lively Member
    Join Date
    Jun 2000
    Location
    Ontario, Canada.
    Posts
    85

    Cool

    I'm guessing that the choices for both combo boxes are being selected from tables in a database. So what I would do is set up the selections for the first combo box. Then the choices for the second combo box must be linked to the first choice. So when you select the first choice, clear the second combo box and use a select statement to fill the combo box selections.

    Like This:

    set rcSet1 = dbConnect.open("SELECT [FIELD1] FROM [TABLE1]")
    do while not rcSet1.eof
    combo1.additem(rcSet1![field1])
    rcset1.movenext
    loop

    private sub combo1_Click()
    combo2.clear
    set rcSet2 = dbConnect.open("SELECT [FIELD2] FROM " & _
    "[TABLE2] WHERE [FIELD1] = '" & combo1.text
    do while not rcSet2.eof
    combo2.additem(rcSet2![field2])
    rcSet2.movenext
    loop
    end sub

    Hope This Helps.





  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Thanks Jim for replying.

    Is that how you do it in Data Environment? Otherwise, I already know how to do it through codes. I am interest in learning the Data Environment.

    Thanks again.
    Chemically Formulated As:
    Dr. Nitro

  4. #4
    Addicted Member
    Join Date
    May 2000
    Posts
    188
    Here's how I would do it using the DataEnvironment. First you would need two command objects in the dataevironment. The first would be your query to fill the first combobox. The second would be for your second combo box and the query that the command uses to return the recordset would use a where clause with a ? to create a parameter. Then in your code you would have something like this in your change event of the first combobox.

    'where Combo2 is the command in the dataenvironment
    DataEnvironment1.Combo2 cbCombo1.Value

    'dataenvironment one would now have a recordset rsCombo2
    'this recordset would then have to be assigned to the
    'second combo box
    cbCombo2.DataSource = DataEnvironment1
    cbCombo2.DataMember = DataEnvironment1.rsCombo2
    cbCombo2.DataField = "FieldName"


    this should do it. Let me know if you have any more questions.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Nathan! Thanks for replying.

    I am still stump on this. This is what I have so far. Can you take a look and tell me what I did wrong?

    Code:
    Private Sub DataCombo1_Change()
      'where Combo2 is the command in the dataenvironment
      DataEnvironment1.Command2 DataCombo1.Text
      
      'dataenvironment one would now have a recordset rsCombo2
      'this recordset would then have to be assigned to the
      'second combo box
      DataCombo2.RowSource = DataEnvironment1
      DataCombo2.RowMember = DataEnvironment1.rsCommand2
      DataCombo2.ListField = "Age"
      
    '  DataCombo2.DataSource = DataEnvironment1
    '  DataCombo2.DataMember = DataEnvironment1.rsCommand2
    '  DataCombo2.DataField = "Age"
    End Sub


    Here is my Command1 SQL:
    SELECT `First Name` FROM Table1

    Here is my Command2 SQL:
    SELECT `First Name`, Age
    FROM Table2
    WHERE (`First Name` = ?)


    Thanks Nathan!
    Chemically Formulated As:
    Dr. Nitro

  6. #6
    Addicted Member
    Join Date
    May 2000
    Posts
    188
    I'm not completely sure. But you could try using "rsCommand2" instead of DataEnvironment1.rsCommand2 not sure if that will do it or not. Is the datasource, datamember and datafield not working?

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