Update 2 fields in a form from one combo box?

JohnGio56

Registered User.
Local time
Yesterday, 21:42
Joined
Feb 12, 2010
Messages
23
How can I update 2 fields from one combo box? I used the combo to update my customer_id but I also want to attach the order_id to the form since it is one of the fields also. I already created the combo box using the wizard and the customer_id updates just fine. I'm just struggling on trying to find a way to also update the the order_id. The combo box displays relevant information so the user knows which account to update. Such as cust_id, order_id, fname, lname, date but the only fields in the form that I want to update is order_id and cust_id. Is there a way to do this? Thanks in advance!
 
Since your combo box already has the OrderID field in it, you can reference it as one of the columns of the combo box.

You get the bound column by just referencing the value returned by the combo box.

You can get any other value from any other column in your combo box (even ones that are not displyed in the list as long as they are one of the columns) by referencing the column in which the value is located. The columns of a combo box or list box use a zero based numbering system. Thus, if the value you want to acquire from the combo box is in the second column, you would refer to column 1, like this:

me.NameOfComboBox.Column(1)

Just refer to one column less than the acutual column count of the column you need.
 
so do i put this in the control source for the field on the form?

would it be typed like so?

me.Combo32.Column(1)
 
You will need to use VBA code. Place the following code in the After Update event of your combo box:

Private Sub Combo32_AfterUpdate()
Me.txtTest = Me.Combo32.Column(1)
End Sub

Change txtTest to the actual name of your text box.
 
Thanks Doc! I'll let you know how it goes! Will you be up for a while? I have another pretty easy question that I'm concerned about. But in order to get there I need to finish this part first. Sorry I'm a newbie but I'm really enjoying this learning process!
 
Okay I'm getting an error that states
Main Menu can't find the macro 'Private Sub Combo32_AfterUpdate()

Any ideas?
 
Sorry, I should have just indicated that you place only this one line:

Me.txtTest = Me.Combo32.Column(1)

in the After Update event of your combo box.
 
I have a combo box with Last Name, First Name and SSN that I am using to input the last name. I could use this to update the SSN field when I choose the Last Name, correct? Would it look like this?

Me.SSN = Me.Combo168.Column(2)

Also, does this go in the After Update of the Last Name? (I assume so but...)
 
You would place the line of code in the After Update event of your combo box.
 
I get an error "Microsft Office Access can't find the object 'Me'"

Where did I go wrong.
 
You may have to post the code are are using or actully post or attache a copy of your database file so we can see it and get it working.

Sometimes, without seeing it, it is really hard to offer specific assistance.
 
I will have to make a sanitized copy and post it here. Thank you for your help.
 

Users who are viewing this thread

Back
Top Bottom