Inserting data into a field when selecting from a combo box

  • Thread starter Thread starter John
  • Start date Start date
J

John

What I am trying to do is utilize a table to allow a user
to choose a list of information from a combo box. What I
want is when a user chooses the information, I not only
want to store that value, but I want to insert another
field from that table into a text box field for the same
record. In summary, I want to know if when I choose a
record from another table, can I insert other fields from
that record to the same record in the new form.

Thanks,
John
 
One way to do this is to use the DLookup function in the
combo box's AfterUpdate event.

Assume:
CName is the name of your combo box
TName is the name of the text field you wish to populate.
Table is the name of the table with the date you want.
Field1 is the field in Table bound by CName (not
necessarily the field that displays).
Field2 contains the data you want from Table.

Set the combo box's AfterUpdate event to be:
Me.TName.Value = Dlookup("Field2", "Table", "Field1 =" &
[Cname]) '(Type this all on one line)

Me.TName.Refresh

See the article on DLookup in Help for more information on
how it works.
 
Back
Top