Populating Fields from previous fields

I would like to populate several fields in a record with data from other fields in the same record. As an example, I would like to fill fields for a mailing address (company, address, city, state, zip) from the fields containing the street address already entered. I would trigger such an event with a checkbox. Can't seem to find the solution to this.

Re: Populating Fields from previous fields

Hi,
There are several ways to do this. The easiest is to use macros. You could use the SetValue macro to set the value of the Target field to the value of the source field.
In the macro, the "Item" argument would be the target item (new field - i.e. "[Forms]![Form1]![txtName2]") and the "Expression" argument would be the source item (original field - i.e. "[Forms]![Form1]![txtName]"). You would have to create an individual line for each text field you wanted to populate. The final step is assigning the "On Click" event of the checkbox to run the macro.

OR If you're comfortable with code, you could set the values of the target fields with the current values of the source fields on the Click event of the checkbox.
The code would be as follows:

Re: Populating Fields from previous fields

Even if you're not comfortable with code, check out this solution at The Access Web

By using the method found there, which is basically setting the default value of a control (field on a form) based on what has been typed in the control, you can run the code conditionally with your check box, or what I like to do is set the code to run on the afterupdate event of the control being filled in.

Basically it will keep using what was typed as the default value until something different is typed, then it will start using that value. Thus no need for the checkbox.

Re: Populating Fields from previous fields

<img src=/S/blank.gif border=0 alt=blank width=15 height=15>
I found the idea of using a checkbox to populate various fields for a mailing address from already entered street address fields very useful.
I tried the code suggested by Mike B and it works fine, except that when I move on to a new record, the checkbox remains either checked or unchecked, depending on what I did with the checkbox in the previous record, ie if I checked the box in the previous record, the box is checked when I move on to a new record, or if I left the checkbox blank, the box is unchecked in the new record.
Ideally, I would like the checkbox to be unchecked when entering new records.
I have tried setting the Default Value of the check box to 0 (unchecked) through the checkbox properties with no success.
By the way, the checkbox is unbound, if that has anything to do with it. I am also using Access 97.
Any ideas?

Re: Populating Fields from previous fields

In the OnCurrent event of the form, put in a line to set the checkbox to false. Since you're using an unbound checkbox, it retains its value between records and you have to tell it to reset itself when you move to a new record.