Combo box select

J

jk

i have a two column combo box with one column for employee number and second
column for employee name. On the form both columns appear but i want to have
the employee number selected and the associated name appear in another text
box.How is this done?
 
D

Daniel

you could use the afterupdate event of the combo box to populate the text
box. Something like,

If isnull(Me.ComboboxName)=False then
Me.TextboxName = Me.ComboboxName.Column(1)
End if

An alternative would be to use dlookup to get the name based on the id.
 
J

John W. Vinson

i have a two column combo box with one column for employee number and second
column for employee name. On the form both columns appear but i want to have
the employee number selected and the associated name appear in another text
box.How is this done?

A third selection, aside from Daniel's two, is to set the combo's Bound Column
property to the one you want stored (the ID); the column widths property can
be set to 0 for the ID if you don't want it visible.

Or, you can put a textbox on the form with a control source

=comboboxname.Column(n)

where n is the *zero based* index of the field you want to display - (1) to
show the second column.

John W. Vinson [MVP]
 
C

Christy Wyatt

The two answers already provided will display the employee name, but if you
want the value to save in the field you can do something like this:

Private Sub cboEmpID_BeforeUpdate(Cancel As Integer)
Set rs = CurrentProject.Connection.Execute("select [EmpName] from Topics
where EmpID = '" & Me.EmpID.Value & "'")
Me.[EmpName] = rs("EmpName")
Set rs = Nothing
End Sub


End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top