Nicola Siotto
asked on
On next/new record, copy specific field data of previous record
I have a form which contains a number of fields. One of these is the department. When I click next it starts a new record but I would like to write on the same field by default the name of the department which can be copied from the previous record. How to do that?
In the attached screenshot video there is a sequence. At first sight on the top left the division is mentioned: Fit Out. When clicking on the next record it disappears, while I'd like to insert automatically the same.
You can use the the AfterUpdate event of your division field to set the default value for that field, something like:
Private Sub txt_Division_AfterUpdate
me.txt_Division.DefaultValue = me.txt_Division
End Sub
You should also use the Form_Current event, like:Private Sub Form_Current
if not me.NewRecord then
me.txt_Division.DefaultValue = me.txt_Division
end if
End Sub
This will make sure that when you enter an existing record, it sets the default to that if you then go to a new record, it has the default value
ASKER
Dear @John and @Dale,
Thank you for your answers and sorry for being late but for three days I was out of station.
In both cases the solution doesn't work for some reasons.
When accessing the form before it opens it gives an error:
Please note that the field "activitytype" is automatically populated from a previous form used as a switchboard.
It worked fine, until I have updated with the formulas.
Thank you for your answers and sorry for being late but for three days I was out of station.
In both cases the solution doesn't work for some reasons.
When accessing the form before it opens it gives an error:
Please note that the field "activitytype" is automatically populated from a previous form used as a switchboard.
It worked fine, until I have updated with the formulas.
Could you upload sample DB with this form and related table with dummy data?
Based on the nature of that error, I would assume that you either referred to a control which does not have a value (a label perhaps). I [ActivityType] a valid control name on your form?
From the note at the bottom of your reply, it looks like this might be a field, not a control. If you don't already have a control bound to the [ActivityType] field, create one, and give it a meaningful name (txt_ActivityType, cbo_ActivityType). Then set the default value of this control.
Normally, when you want to set the default value of a control, it is when you just finished entering data for a record and you want to repeat many of the values when you create the next record. In that case, a better event for setting the default value of a control is in the AfterUpdate event of that control.
Dale
From the note at the bottom of your reply, it looks like this might be a field, not a control. If you don't already have a control bound to the [ActivityType] field, create one, and give it a meaningful name (txt_ActivityType, cbo_ActivityType). Then set the default value of this control.
Normally, when you want to set the default value of a control, it is when you just finished entering data for a record and you want to repeat many of the values when you create the next record. In that case, a better event for setting the default value of a control is in the AfterUpdate event of that control.
Dale
ASKER
Tomorrow I will try to upload a sample. Thanks.
ASKER
@als315 as advised yesterday I have created a sample.
There is only one form and if opened there is a combo with the activities that are created from the main table. Now, what I wish is that when pressing NEXT on the bottom of the form to create a new record, automatically the control named [activitytype] is populated with the same content of the previous record. Is that possible?
Sample.mdb
There is only one form and if opened there is a combo with the activities that are created from the main table. Now, what I wish is that when pressing NEXT on the bottom of the form to create a new record, automatically the control named [activitytype] is populated with the same content of the previous record. Is that possible?
Sample.mdb
How should it work? Form looks not very likely to your form on video.
Should I select Division (activitytype) and press new record button?
Is expected behaviour - fill activitytype in new record equal to selected on form?
Should I select Division (activitytype) and press new record button?
Is expected behaviour - fill activitytype in new record equal to selected on form?
ASKER
@als315 correct. It’s like you wrote, exactly.
What Division should be copied to new record? From last selected record? Or from last record in table?
ASKER
@als315
from last record
from last record
ASKER
@john
I'm not at my pc right now so I cannot test it. Will do so later. Thabks.
I'm not at my pc right now so I cannot test it. Will do so later. Thabks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@John the sample that you have sent doesn't do the job. When I go to the new record the control is empty.
ASKER
@als315 I have opened the form frm_main and it works perfectly.
Is there any reason why it didn't work on the form _CPR_NEW?
Is there any reason why it didn't work on the form _CPR_NEW?
Form _CPR_NEW is strange. It is limited only to new record, but I was not able to find reason in reasonable time. It's take too many time to analyze difference between forms.
ASKER
In any case I have replicated the functions and works fine. Thanks.
It is limited only to new recordThis is because of the Data Entry flag.
e.g.
Dim department
....
On Some event e.g
AfterUpdate
department = me.department
then on the Current
if Me.NewRecord Then
If department <> 0 then
me.department = department
End if