Combo Box Question

MrMitch

Registered User.
Local time
Today, 09:58
Joined
Oct 19, 2007
Messages
50
I have a combo box on a form that pulls data from the first column of a table, however I need to drop whatever is in the 2nd column of that selection in a seperate text box automatically. Is there a way to do this? If so, any guidance would be appreciated. Thanks!
 
With the form in design view, right click the combo/list box and select
Build Event, then Code Builder.

Select BeforeUpdate from the top right corner.

Enter the following code between the 2 existing lines.

Private Sub Combo55_BeforeUpdate(Cancel As Integer)

[fieldname] = ([Combo55],#)

End Sub

The [fieldname] is the name of the field you want to copy the data to.
Combo55 is the number of the combo box you're using.
The # refers to the column in the combo box. The columns start with number 0 (zero) in the left most column and increases by 1 for each column you move to the right. The third column from the left would therefore be column 2.

Each column you wish to copy when you select a record in the combo box needs its own line of code.

When you created the combo box using the wizard, you had the option of saving one of the columns into a field at that time. If you did this, you don't have to use the code to save that column, it’s already done.
 
As sated, columns in a combobox start at 0 then 1 then 2, etc. So, for the second column:

Code:
Private Sub YourComboBox_AfterUpdate()
 Me.YourControlName = Me.YourComboBox.Column(1)
End Sub

Linq
 
Thank you both for your help, got it working now.
 

Users who are viewing this thread

Back
Top Bottom