简体   繁体   中英

Access combo box filling text box

I want to use the table "services" which is filled with (id, service, price) at the moment i have a combo box (combo51) which lists all of those. now i have to get price from the selected thing in the combo box and get the price for it.

i have a query, but honestly i have no idea how to apply it to the text box and if it would even work.

SELECT price
FROM services
WHERE Services="Combo51";

From what i've seen in other topics they don't really make much sense to me, if someone could just explain basically what i have to do it'd be appreciated.

You shouldn't need to query the db after the combobox values are populated. Set the bound column property of the combobox to whatever value you want, and access it with combo51.value

If you insist on querying the db again, try something like this (assuming ID is the bound column):

msgbox dlookup("price", "services", "id=" & combo51.value)

You are already halfway. In the VBA code dialog, you can refer to the ID easily, eg

 Debug.Print Combo51

but if you want the price, assuming the price is the third column in your table, use

 Debug.Print Combo51.Columns(2)

So, if you want it displayed in a separate text box, add an 'On Change' event to the combo box and add the following code:

 TextBox = Combo51.Columns(2)

Now every time you make a selection in the combo box the price will be displayed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM