How to automatically populate fields in a form

G

Guest

Hello,

I have a database that has a form with a field in it containing a drop down.
The drop down looks up values in a table in the database. Based on the
choice for that field, I'd like 3 other fields on that form to be
autopopulated based on the choice in the drop down. (that underlying table
has information in it that i want to have automatically plugged into those 3
fields)

For example:

I have a "LocalContact" field that looks up values in an underlying table
(tblContactInfo). Based on that selection, i'd like that contact's phone
number and office automatically filled in on that form based on those
corresponding values in that tblcontactinfo table.

Thank you in advance for your help!

MN
 
D

Douglas J. Steele

Make sure that the combobox is based on a query that returns all 4 of the
fields of interest (even if you set their width to 0 so that they don't
display when the

In the combobox's AfterUpdate event, put code to populate the other 3
fields.

You refer to the additional fields of the selected row in the combobox as
Me!MyComboBox.Column(0), Me!MyComboBox.Column(1) and so on (replace
"MyComboBox" with whatever your combobox is called)
 
G

Guest

I checked and the combobox DOES return all values in the query. This is my
code in the after update event of my combo box:

Me![contact].Column(2) = tblContactInfo!Office.Value
Me![contact].Column(3) = tblContactInfo![Phone #].Value

I get an error saying that an "object is required" ....can you see what i'm
doing wrong?

Thanks!
 
D

Douglas J. Steele

You can't set the Column values: they're read-only.

You can set the values of other controls to them, though.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



MacNut said:
I checked and the combobox DOES return all values in the query. This is my
code in the after update event of my combo box:

Me![contact].Column(2) = tblContactInfo!Office.Value
Me![contact].Column(3) = tblContactInfo![Phone #].Value

I get an error saying that an "object is required" ....can you see what
i'm
doing wrong?

Thanks!

Douglas J. Steele said:
Make sure that the combobox is based on a query that returns all 4 of the
fields of interest (even if you set their width to 0 so that they don't
display when the

In the combobox's AfterUpdate event, put code to populate the other 3
fields.

You refer to the additional fields of the selected row in the combobox as
Me!MyComboBox.Column(0), Me!MyComboBox.Column(1) and so on (replace
"MyComboBox" with whatever your combobox is called)
 
D

David C. Holley

Basically in the AfterUpdate event of the combo box

[Forms]![myFormName]![fieldName] = [Forms]![myFormName]![comboBox].column(1)

or
[Forms]![myFormName]![fieldName] = DLookup()

The first method requires that the RowSource of the comboBox contain the
columns that will be pulled into the other fields.

David H
 
G

Guest

Works like a charm, thank you very much!!! :)

David C. Holley said:
Basically in the AfterUpdate event of the combo box

[Forms]![myFormName]![fieldName] = [Forms]![myFormName]![comboBox].column(1)

or
[Forms]![myFormName]![fieldName] = DLookup()

The first method requires that the RowSource of the comboBox contain the
columns that will be pulled into the other fields.

David H
MacNut said:
Hello,

I have a database that has a form with a field in it containing a drop down.
The drop down looks up values in a table in the database. Based on the
choice for that field, I'd like 3 other fields on that form to be
autopopulated based on the choice in the drop down. (that underlying table
has information in it that i want to have automatically plugged into those 3
fields)

For example:

I have a "LocalContact" field that looks up values in an underlying table
(tblContactInfo). Based on that selection, i'd like that contact's phone
number and office automatically filled in on that form based on those
corresponding values in that tblcontactinfo table.

Thank you in advance for your help!

MN
 

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