ComboBox fields to Update record in a table

L

LMB

Hi,

I have this exercise below working. Now I want to know if I can have my combo box on a form that has the record source set to another table and I want to select the names from my combo box multiple times to fill in fields on the form that will update my other table. I would be using the tblPersons as a lookup table and wanted the information when clicked on to automatically be entered into this other table.

example:

tblPersons is a lookup table with FName, LName, my combo box displays these names
tblAuditor is a table that has names of persons

I want to click on the combo box with the person's name and it insert the person's name in the FName field and LName field of the tblAuditor.

Thanks,
Linda



(Q) How do I have a textbox automatically fill in with a value after I select an item from a combo box on a form (e.g., select a person's ID in a combo box, and have the person's last name automatically display in a textbox)?

(A) The way to do this depends upon whether the textbox is bound to a field in the form's Record Source or not.

Unbound Textbox
In this example, we'll assume that your desired information is in a table named tblPersons, and that this table contains four fields: ID (the person's ID); FirstName (the person's first name); MiddleName (the person's middle name); and LastName (the person's last name).

Set the Row Source Type property of the combo box (assume it's named cboPersonID) to "Table/Query". Set the Row Source to a query that is based on tblPersons and that selects the ID and LastName fields:



' ***** Code Start *****
SELECT ID, LastName
FROM tblPersons
ORDER BY ID;
' ***** Code End *****Set the Bound Column property of cboPersonID to 1.
Set the Column Count property to 2.
Set the Column Widths property to this expression: 1";0".

Set the Control Source of a textbox (assume it's named txtPersonName) to this expression:

=[cboPersonID].[Column](1)

Note that the Column property of a combo box is "zero-based," meaning that the first column (field) in the combo box's Row Source is column 0, the second column is column 1, etc.

When you make a selection of a person's ID in the combo box, the textbox will automatically display the person's name. You can extend this example to include more textboxes by adding more fields to the combo box's Row Source query and setting the Control Source of each textbox to the appropriate column number of the combo box.
 
J

John Vinson

Hi,

I have this exercise below working. Now I want to know if I can have my combo box on a form that has the record source set to another table and I want to select the names from my combo box multiple times to fill in fields on the form that will update my other table. I would be using the tblPersons as a lookup table and wanted the information when clicked on to automatically be entered into this other table.

example:

tblPersons is a lookup table with FName, LName, my combo box displays these names
tblAuditor is a table that has names of persons

I want to click on the combo box with the person's name and it insert the person's name in the FName field and LName field of the tblAuditor.

Ummm...

No. You really *don't* want to do this.

The whole POINT of a relational database like Access is that you avoid
redundnancy, thereby avoiding redundancy. If you store the person's
name once in the People table, that is the ONLY place where it should
be stored! Your tblAuditor should have a field for the PersonID (bound
to the combo box on your form) - and ONLY the PersonID. Storing the
FName and the LName in tblAuditor wastes space, and causes big hassles
if the person changes their name.

If you want to see the auditor's name, use a Query linking the two
tables by PersonID; pull the name from the People table, and the other
auditor information from the Auditor table.

And... take a look at http://www.mvps.org/access/lookupfields.htm for
a critique of Microsoft's misdesigned, misleading and obnoxious
so-called "Lookup" field type.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
L

LMB

Hi,

I have this exercise below working. Now I want to know if I can have my combo box on a form that has the record source set to another table and I want to select the names from my combo box multiple times to fill in fields on the form that will update my other table. I would be using the tblPersons as a lookup table and wanted the information when clicked on to automatically be entered into this other table.

example:

tblPersons is a lookup table with FName, LName, my combo box displays these names
tblAuditor is a table that has names of persons

I want to click on the combo box with the person's name and it insert the person's name in the FName field and LName field of the tblAuditor.

Ummm...

No. You really *don't* want to do this.

The whole POINT of a relational database like Access is that you avoid
redundnancy, thereby avoiding redundancy. If you store the person's
name once in the People table, that is the ONLY place where it should
be stored! Your tblAuditor should have a field for the PersonID (bound
to the combo box on your form) - and ONLY the PersonID. Storing the
FName and the LName in tblAuditor wastes space, and causes big hassles
if the person changes their name.

If you want to see the auditor's name, use a Query linking the two
tables by PersonID; pull the name from the People table, and the other
auditor information from the Auditor table.

And... take a look at http://www.mvps.org/access/lookupfields.htm for
a critique of Microsoft's misdesigned, misleading and obnoxious
so-called "Lookup" field type.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps




Oh boy, foiled again. Can't I just do it this one last time? I promise, I'll be good from now on and will never ever do it again. I'll send cookies, beef jerky, jelly beans. I'll even read that article right now..............Linda
 
T

tina

Oh boy, foiled again. Can't I just do it this one last time? I promise, I'll be good from now on and will never ever do it again. I'll send cookies, beef jerky, jelly beans. I'll even read that article right now..............Linda

ah, Linda is really testing your "use a relational database relationally" integrity, John! can you withstand the temptation?? (hmm, i wonder if those are homemade *chocolate chip* cookies...) <g>


Hi,

I have this exercise below working. Now I want to know if I can have my combo box on a form that has the record source set to another table and I want to select the names from my combo box multiple times to fill in fields on the form that will update my other table. I would be using the tblPersons as a lookup table and wanted the information when clicked on to automatically be entered into this other table.

example:

tblPersons is a lookup table with FName, LName, my combo box displays these names
tblAuditor is a table that has names of persons

I want to click on the combo box with the person's name and it insert the person's name in the FName field and LName field of the tblAuditor.

Ummm...

No. You really *don't* want to do this.

The whole POINT of a relational database like Access is that you avoid
redundnancy, thereby avoiding redundancy. If you store the person's
name once in the People table, that is the ONLY place where it should
be stored! Your tblAuditor should have a field for the PersonID (bound
to the combo box on your form) - and ONLY the PersonID. Storing the
FName and the LName in tblAuditor wastes space, and causes big hassles
if the person changes their name.

If you want to see the auditor's name, use a Query linking the two
tables by PersonID; pull the name from the People table, and the other
auditor information from the Auditor table.

And... take a look at http://www.mvps.org/access/lookupfields.htm for
a critique of Microsoft's misdesigned, misleading and obnoxious
so-called "Lookup" field type.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps




Oh boy, foiled again. Can't I just do it this one last time? I promise, I'll be good from now on and will never ever do it again. I'll send cookies, beef jerky, jelly beans. I'll even read that article right now..............Linda
 
L

LMB

Yep, they are! Homemade Beef Jerky too!
tina said:
Oh boy, foiled again. Can't I just do it this one last time? I promise, I'll be good from now on and will never ever do it again. I'll send cookies, beef jerky, jelly beans. I'll even read that article right now..............Linda

ah, Linda is really testing your "use a relational database relationally" integrity, John! can you withstand the temptation?? (hmm, i wonder if those are homemade *chocolate chip* cookies...) <g>


Hi,

I have this exercise below working. Now I want to know if I can have my combo box on a form that has the record source set to another table and I want to select the names from my combo box multiple times to fill in fields on the form that will update my other table. I would be using the tblPersons as a lookup table and wanted the information when clicked on to automatically be entered into this other table.

example:

tblPersons is a lookup table with FName, LName, my combo box displays these names
tblAuditor is a table that has names of persons

I want to click on the combo box with the person's name and it insert the person's name in the FName field and LName field of the tblAuditor.

Ummm...

No. You really *don't* want to do this.

The whole POINT of a relational database like Access is that you avoid
redundnancy, thereby avoiding redundancy. If you store the person's
name once in the People table, that is the ONLY place where it should
be stored! Your tblAuditor should have a field for the PersonID (bound
to the combo box on your form) - and ONLY the PersonID. Storing the
FName and the LName in tblAuditor wastes space, and causes big hassles
if the person changes their name.

If you want to see the auditor's name, use a Query linking the two
tables by PersonID; pull the name from the People table, and the other
auditor information from the Auditor table.

And... take a look at http://www.mvps.org/access/lookupfields.htm for
a critique of Microsoft's misdesigned, misleading and obnoxious
so-called "Lookup" field type.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps




Oh boy, foiled again. Can't I just do it this one last time? I promise, I'll be good from now on and will never ever do it again. I'll send cookies, beef jerky, jelly beans. I'll even read that article right now..............Linda
 
J

John Vinson

Oh boy, foiled again. Can't I just do it this one last time? I promise, I'll be good from now on and will never ever do it again. I'll send cookies, beef jerky, jelly beans. I'll even read that article right now..............Linda

LOL!

Cookies maybe. I'll pass on the beef (I've been vegetarian since
1970).

Apologies if my rant came over as excessively didactic... it was meant
well!


John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
L

LMB

Oh boy, foiled again. Can't I just do it this one last time? I promise, I'll be good from now on and will never ever do it again. I'll send cookies, beef jerky, jelly beans. I'll even read that article right now..............Linda

LOL!

Cookies maybe. I'll pass on the beef (I've been vegetarian since
1970).

Apologies if my rant came over as excessively didactic... it was meant
well!

John,
I just was hoping now one would notice what I was up to. <g> I have it worked out now. Thanks

Linda
 

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