Text Field Change on Combo

G

Guest

I'm trying to get a text field to automatically display the name of the
vendor that I've selected in my combo box. The Vendor ID (12345) is in the
first column in my table. The Vendor Name (Vendor) is in the second column
in my table.
 
R

ruralguy via AccessMonster.com

In the ComboBox AfterUpdate event put:
Me.YourTextBoxName = Me.ComboBoxName.Column(1)

Using your names of course. The index is zero based so 1 is the 2nd column.
 
R

Ron2006

There are two ways of doing it.

1) in the control source of the txt field place
=me.comboboxname.column(1) ' count is relative to 0

2)
In the afterupdate event for field AND
in the OnCurrent event on form place
me.txtboxname = me.comboboxname.column(1)



Ron
 
G

Guest

Sean,

Another approach is to not worry about the ID at all. Bind the combo box to
the ID (Bound Column = 1), but display the name in the drop-down (Set Column
Widths to 0", x", where x is large enough to display the longest name). Sort
by the company name, e.g., set the Row Source to:

SELECT Vendors.VendorID, Vendors.CompanyName FROM Vendors ORDER BY
Vendors.CompanyName;

You may also wish considering a single table for all Companies--vendors,
customers, reps, etc., and use a field to distinguish them. Your forms can
then be based on queries that select the appropriate subset. If you have
companies that are both a supplier, a rep, a customer--as is common in my
business--rather than use a single field, you can use a detail table that
would allow a company to be coded to more than one type.

CompanyTypes
------------------
CompanyID
CompanyType

Hope that helps.
Sprinks
 
G

Guest

No good. Now I get a pop-up, "The expression On Load you entered as the even
property setting produced the following error: Invalid outside procedure."
 
R

ruralguy via AccessMonster.com

Hi Sean,
What I posted should go in the AfterUpdate event of the ComboBox and not the
OnLoad event of the form. As others have suggested, you will probably need
similar code in the Current event of the form for proper display under all of
the conditions.
No good. Now I get a pop-up, "The expression On Load you entered as the even
property setting produced the following error: Invalid outside procedure."
In the ComboBox AfterUpdate event put:
Me.YourTextBoxName = Me.ComboBoxName.Column(1)
[quoted text clipped - 5 lines]
 

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

Top