Question : Populate Text box based on combo box

I want to populate a text box on a form based upon the selection of a combo box.  I have a customer table linked to a contact table based on their id (auto#). One customer can have many contacts.  Currently, cbo.customer selects the customer, cbo.contacts selects contacts based upon the customer and returns the contact id.  I have address fields, city state phone etc in the form bound to a table.  I want to pull the information from the contact table into the form to be saved as part of the record in another table.   I'm familiar with Access GUI, a beginner with VBA and need help.  Hopefully, this will seem easy to someone out there!!  I can upload the file if it would help.

Answer : Populate Text box based on combo box

Which form? If it is "ContactDetails", I can't open it because "Contacts Extended" does not exist in the database. I assume it is EstInput _frm.  I am guessing you want to fill out the text boxes on that form when you select a ContactID.  I did that for three of your textboxes (two different ways) - I assume you can figure out the others.

Some other points:
In your query Sel_Contact, you have linked the two tables on the company name. Don't do that!!! It will fail if you have two companies with the same name or it the name is misspelled in one table. Place a long field in the Contacts table and link it to the ID field in the Customer_tbl table. This is called Primary key to Foreign key linking (Foreign key in the contacts table in this case). You also have duplicate information in both tables. Don't do that either. Read about Database normalization in Wikipedia.

In your query Sel_Contact, the reference [frm]![Estinput_frm]![custname] failed.  The correct syntax is [Forms]![Estinput_frm]![custname] but that also failed because the form name is really [EstInput _frm] (see the extra space?). See the section below about avoiding spaces and other special characters. You had the field and criteria reversed also.

It is best to avoid spaces, underscores and other special characters in your naming of objects. For example: CountOfPeopleLive is just as easy to read as Count Of People_Live.  Objects named with special characters including spaces need to be placed in brackets for Access to recognize them correctly. Here is an extreme example of the problems you will have using special characters in your names:
I named a textbox
!@#$%^&*()_+= -{}:;"'<,>?/|~
and had Access create an event procedure.  Access converted the name of the textbox to:
Ctl_____________________________
so if the form had the name:
~!@#$%^&*()_+= -{}:;"'<,>?/|~
referencing the textbox would be:
Forms!l_____________________________!Ctl_____________________________
A useful tip for someone who doesn't want someone else (probably even themselves) from reading their code.
And spaces will sometimes cause problems in VBA references even after years of trouble free operation.

It is also a good idea to use a naming scheme such as Leszynski naming conventions (see references). It makes it clearer what type of object you are naming and it reduces the risk of duplicate name problems (like a control name and its control source).

References:
http://www.xoc.net/standards/rvbanc.asp
http://www.dhdurso.org/articles/ms-access-naming.html
http://www.acc-technology.com/namconv.htm
http://www.databasedev.co.uk/naming_conv.html
http://en.wikipedia.org/wiki/Leszynski_naming_convention
 
 
Random Solutions  
 
programming4us programming4us