How can I populate a textbox on a form from a selection from a combobox?

Hi, regular listener, first time caller! :slight_smile:
I have a database with the tables ‘tblGear’ and ‘tblManufacturers’.
The Gear table has lots of fields in, amongst which are the fields ‘Manufacturer’ and ‘ManufacturerID’.
I have a form which populates the Gear table (tblGear) successfully, with a combo box with a drop down to select the Manufacturer name from the Manufacturers table (tblManufacturers) when entering a new item in the gear table.
My question is, can I put a textbox or other control on the AddGear form which will get the ManufacturerID from the Manufacturers table and add it to the Gear table? (ie, when the Manufacturer name is selected in the combobox, the ManufacturerID is automatically populated on the entry form and is added to that Gear record in the Gear table)?
Hope I’ve explained this, probably really simple, question OK (very new to the Base family!)
Thanks in advance :slight_smile:

You only need “ManufaturerID” in ‘tblGear’ Storing the 'Manufacturer’ in ‘tblGear’ table opens the door for inconsistent data issues and violates the rules of good database design ( Normalization in database jargon)

On your AddGear form use a ListBox to select the ManufacturerID. A query for a ListBox has two fields, a Display Field and a Boundfield.

In your case the query for the ListBox would look something like

SELECT “Manufacturer”, “ManufacturerID” FROM “tblManufacturers” ORDER BY “Manufacturer” ASC;

If you run the query it should display a list of Manufacturers in alphabetical order along with the associated ManufacturerID.

When that query is used with a ListBox control you should see a drop down list of Manufacturers (the Display Field) and when you make a selection the ListBox will store the ManufaturerID (the Boundfield) in tblGear.

1 Like