PDA

Click to See Complete Forum and Search --> : combo box


HunterMcCray
Aug 25th, 2000, 02:12 PM
Originally posted by loverpal
Well how do u connect a combo box bounded to a primary key field in (table a) to show the content of a field in (table b) in a text box. Table b and a are connected bye the primary key of (table a).

You can bind the text box to the data control by setting the recordsource of the text box to the data control that binds the combo box then set the recordsource of the text box to the same data control. You must use a dynaset in the the data control's recordsource property that joins the two tables. You can do this by creating a query in MS Access or through an SQL statement.

In this example two tables are joined by idref and the customers name would be in your combo box and the customer's phone number would appear in your text box:

txtSQL= "SELECT CustNew.Nam1, PhoneInfo.PhoneNumber
txtSQL= txtSQL & "FROM CustNew LEFT JOIN PhoneInfo ON txtSQL= txtSQL & "CustNew.IdRef= PhoneInfo.IdRef;"

data1.recordsource=txtSQL
data1.refresh

If the recordsource of the dbCombo is set to data1 and the data field is set to Nam1 AND the datasource of the textbox is set to data1 and the data field is set to PhoneNumber then the text box will display the current PhoneNumber for the customer selected in the dbCombo. If you want to make the text box display the PhoneNumber for the record highlighted in the dbCombos list (but not selected) the case requires code instead of the simple solution presented above.

Hunter

loverpal
Aug 25th, 2000, 02:47 PM
thanx.. i'll try it...