Click to See Complete Forum and Search --> : Lenin - Data Environment
Nitro
Jun 21st, 2000, 05:27 AM
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.
Jimmer
Jun 21st, 2000, 10:25 AM
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.
Nitro
Jun 21st, 2000, 11:36 PM
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.
Nathan
Jun 22nd, 2000, 01:07 AM
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.
Nitro
Jun 22nd, 2000, 01:41 AM
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?
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!
Nathan
Jun 22nd, 2000, 02:10 AM
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?
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.