Combo box select

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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.
 
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]
 
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
 
Back
Top