Combo Box Data Storage

Jkittle

Registered User.
Local time
Today, 14:12
Joined
Sep 25, 2007
Messages
100
I have created a query the gives me a supplier number and the supplier name.

I want to use a combo box on a form to select the supplier number and be able to see the supplier name in a text field and store the information in a table.

Can this be done?
 

Attachments

You'll need to place a textbox on the form to hold the supplier's name, we'll call it txtSupplierName in this example, then use this code in your combobx, which is named Combobox26 in your posted db. You really need to give your control meaningful names instead of settling for theAccess assigned names:

Code:
Private Sub Combo26_AfterUpdate()
 Me.txtSupplierName = Me.Combo26.Column(1)
End Sub
You'll also need to set the Control Source of the textbox to a field in your underlying table/query.
 
What field or where in the combo box does the code go?
 
In Design View, select the combobox

Goto Properties - Event

Click in the “AfterUpdate” property box

To the right of this box a small square will appear with an ellipsis [...]

Click on the ellipsis

A dialog box will come up with the options “Expression Builder” “Macro Builder” and “Code Builder”

Click on “Code Builder”

You will be taken into the code window, also called the code module or code editor, and will see something like this

Code:
Private Sub Combo26_AfterUpdate()

End Sub

Now you need to enter the line of code you were given

Me.txtSupplierName = Me.Combo26.Column(1)

into this empty sub, so that you end up with

Code:
Private Sub Combo26_AfterUpdate()
 Me.txtSupplierName = Me.Combo26.Column(1)
End Sub

You’re now done. Either goto “View” on the menu and click on “Object” or look for the icon with the Access “Key” and click on it. This will take you back to the form’s Design View.

Here's Bob Larson's site that has some great graphics demonstrating the same thing:

http://www.btabdevelopment.com/main/QuickTutorials/Wheretoputcodeforevents/tabid/56/Default.aspx
 
Thank you for your help and patients with someone who hasn’t used Access in a long time.

It worked perfect.

Jerry:)
 
I have created a query the gives me a supplier number and the supplier name.

I want to use a combo box on a form to select the supplier number and be able to see the supplier name in a text field and store the information in a table.

Can this be done?
Why would you not just store the bound column?:confused:
 

Users who are viewing this thread

Back
Top Bottom