View Full Version : Getting a Field to popluate with table info


Steel
09-07-2001, 04:36 PM
Hi..I need to know how on a form to get a field to populate the other fields base on the value you input into that field.. Example: I want to be able to have my field named "Employee Name" to automatically update once I have input the Employee Number in the previous field. This is a small example but eventually I want to input the employee name and all other info about that employee to populate the various fields based upon that employee number.

jwindon
09-08-2001, 06:27 AM
So the form you are using is NOT based on the table that contains this information. That's fine. What you will need to do first is create a query that draws together all the information you will want to populate the form fields (the other table). I am assuming that you want to store that information. If not, use Dlookup to show the name, etc.

Put a combobox on your form based off the query you created.
On you form, show the fields you want populated.
On the AfterUpdate event of the combobox, put this code.

Me.NameField = ComboBoxName.Column(1)
Me.AddressField = ComboBoxName.Column(2)
etc.

That is an example. I don't know what your fields are named.

Anyway, the columns that are in your combo begin with 0 and then 1,2,3...

If you would rather use Dlookup, post back.

R. Hicks
09-08-2001, 08:12 AM
If you have your database properly "Nomalized" and you have your "Relational Joins" also correct, you only need to add the table that contains the EmployeeInfo into the Recordset query that the form is based on. All needed info for the employee will populate your controls as soon as the ID from the table is identified through the Relational Joins. "You will not need an event procedure to do this".

The info from the EmployeeInfo table should not be stored in the main table in this process. All that should be stored in the main table is the Record ID from the EmployeeInfo table. Then this info can be produced "dynamically" when needed again through the use of the Relational Joins as explained above.

HTH
RDH

[This message has been edited by R. Hicks (edited 09-08-2001).]

KyleB
09-18-2001, 09:54 AM
Along the same lines, I've got similar things in my forms, and using this info I was able to get associated text boxes to display the proper information when a combo box was changed. My question however is this; How do you clear the contents of those text boxes when you exit that record and proceed to the next record? My text boxes are unbound, and I'm using them exclusively for informational purposes. They contain calculated values based on the information entered by the user, as a check etc as they're entering the data. As it stands however, the data in the text boxes is carried over to the next record, which I don't want to happen, and I can't find a "Clear" command that could be put in. Any suggestions?

Kyle B.

Pat Hartman
09-18-2001, 12:32 PM
Steel,
I would add one thing to Rick's answer. Set the enabled property to no and the locked property to yes for those fields that are stored in the related table. Usually, you do not want them to be updated accidentally via a form where they are only used for reference.

Kyle,
On a continuous form, the values in unbound controls will be identical for all rows that are visible on the form. This is because the unbound field is associated with the form and therefore occurs only once, rather than being stored in the table where it would occur once for each row. If your form is in single view, you can clear the unbound fields in the OnCurrent event.

Me.SomeField = ""