PDA

Click to See Complete Forum and Search --> : ADO Combo Box and Fields


Cam
May 1st, 2000, 04:12 PM
Hi everyone, I am new here. I have looked everywhere for an answer to this one. I have created a combo box using ADO datasource. I have the combo box working by placing the datasource and datafield values in. I then set the rowsource and listfield in also. My question is: I now want to choose a record in the combo box and from that related data fill two text boxes with the related data. I know this can work but I don't know how. Can anyone help me???

Edneeis
May 2nd, 2000, 02:15 PM
Well here is one way of doing it. I assume you are using the datacombo box. One way is to Filter the recordset by the text in the combobox. So if my ADO control or data environment is ADO1 then inside the datacombo click event put:

Private Sub PtNameCmb_Click(Area As Integer)
If Area = 2 Then
ADO1.Recordset.Filter = "PtName LIKE '" & PtNameCmb.Text_ & "'"
End If
End Sub

Area=2 makes sure the click is in the drop down box and PtName is the field i want to search by. PtNameCmb is the name of my datacombo box. It is also a good idea to enclose the filter search in a:
If PtNameCmb.text<>"" then

end if
statement so you don't search when the text is empty.
WARNING if the PtName isn't found in the recordset then it will return an error so put some error handling in for that.

There is also the ADO1.Recordset.Find method look that up in the help, but it only works if you are searching a table with an index, no queries or anything. Good luck I hope that helped.

Cam
May 4th, 2000, 08:36 AM
I have the ADO selecting a table full of data called household. One field is Surname. I have my combo box list the surname. I now want a text box to give me the address where the householdid = the current combo box householdid. Householdid, surname and address all come from the same table. I am using a datacombo box.

Edneeis
May 4th, 2000, 01:42 PM
Are you using the ADO control? Data Environment? DAO?
Did you set the datasource, member, and fields of the other textboxes that you want to display the other info?

It should go something like this:
(set at design time)
DCombo1.Rowsource=ADO1
(All of the datamember properties only need to be set if you are using the data environment otherwise just leave that out)
DCombo1.Rowmember=Household
DCombo1.ListField=Surname
Text1.datasource=ADO1
Text1.datamember=Household
Text1.datafield=Address
Text2.datasource=ADO1
Text2.datamember=Household
Text2.datafield=HouseholdId

In the click event of the DCombo1 have something like this:
Private Sub DCombo1_Click(Area As Integer)
If Area=2 then
ADO1.Recordset.filter="SurName LIKE '" & DCombo1.text & "'"
End if
End Sub

The filter makes only the records matching the criteria set show up in the recordset. So if there are more then one of the surname you would have to .MoveNext through them or filter by a unique field maybe HouseholdId instead. But it will update all the controls linked to the same recordset, thus changing the address and Id accordingly. Try that!