Combo Box to Update Text/Label

Badswell

Registered User.
Local time
Today, 19:41
Joined
Feb 13, 2004
Messages
34
On a form I have a combo box that lists companies names. Each company has a number code assigned to each. Below the combo box, a text box is there that would display this number based on the user's choice in the combo box.

I can't get the text box to update automatically based on what company is picked. Any ideas?
 
Private Sub cboYourCombo_AfterUpdate()
Let lblYourLabel.Caption = cboYourCombo.Column(0)
End Sub

Put the above code in the after update event of your combo box substituting cboYourCombo with your combo box name and lblYourLabel with your label name.
 
Still having some issues with this. Here's the code that drives my combo box:

Form: [Current_TNC]
Combo Box for Name: [curr_tnc_supp_name]

SELECT [PS_Supplier_Info].[SUPRO_Supplier_Name], [PS_Supplier_Info].[SUPRO_Current_ Supplier] FROM PS_Supplier_Info WHERE ((([PS_Supplier_Info].[SUPRO_Current_ Supplier])="1"));

This displays a list of supplies Names. Depending on the name chosen, I need the corresponding supplier number ([PS_Supplier_Info].[SUPRO_Supplier_No]) to display in a text box or label that is shown below the combo.

Temporarily, I have this working by a 2nd combo box using:

SELECT [PS_Supplier_Info].[SUPRO_Supplier_No] FROM PS_Supplier_Info WHERE (([PS_Supplier_Info]![SUPRO_Supplier_Name]=[Forms]![Current_TNC]![curr_tnc_supp_name]));

This code does work, however once the first name is selected, the number is still needed to be selected. The 2nd code queries the [PS_Supplier_Info] table based on criteria of the name selection from the 1st combo box.

I am looking to remove the manual step of choosing the number.
 
Change the code in your combo box “curr_tnc_supp_name” from this:

SELECT [PS_Supplier_Info].[SUPRO_Supplier_Name], [PS_Supplier_Info].[SUPRO_Current_ Supplier] FROM PS_Supplier_Info WHERE ((([PS_Supplier_Info].[SUPRO_Current_ Supplier])="1"));


to this:

SELECT [PS_Supplier_Info].[SUPRO_Supplier_No],[PS_Supplier_Info].[SUPRO_Supplier_Name], [PS_Supplier_Info].[SUPRO_Current_ Supplier] FROM PS_Supplier_Info WHERE ((([PS_Supplier_Info].[SUPRO_Current_ Supplier])="1"));

And then use the code from previous post. If that works, :D You may need to hide the extra column in your combo. Post back if you do…
 
Thanks for the help on this. The code does work & the number displays once a name is chosen. However I think the a column does need to be hidden because the combo is showing the supplier # rather than the name.
 
What you need to do is get to the combo box properties, on the format tab change the column count to 2, And change the column widths to 0cm; 2.54cm. This will hide the first column .
 

Users who are viewing this thread

Back
Top Bottom