Subforms being locked

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

With Access 2003, I'm having an issue today I haven't ever had before. I
have a form with three subforms on it. On the main form, I set the
Form_AfterUpdate event with the following code.

Private Sub Form_AfterUpdate()

Me.DateOfChange = Date

End Sub

When a user does make a change, the subforms are locking - I can't change
data in them, nor can I hit the "design form" button on my toolbar to make a
change. I have to close the form altogether and re-open it to do any design
work.

The idea is that any time I have a change on the form, I want the "Date of
Last Change" field to update to today. I don't want it to change if someone
just looks at the data - this form is used for both updates and reference.

Does anyone have a solution to this problem?

Thanks,
Jamie
 
Jamie said:
With Access 2003, I'm having an issue today I haven't ever had before. I
have a form with three subforms on it. On the main form, I set the
Form_AfterUpdate event with the following code.

Private Sub Form_AfterUpdate()

Me.DateOfChange = Date

End Sub

When a user does make a change, the subforms are locking - I can't change
data in them, nor can I hit the "design form" button on my toolbar to make a
change. I have to close the form altogether and re-open it to do any design
work.

The idea is that any time I have a change on the form, I want the "Date of
Last Change" field to update to today. I don't want it to change if someone
just looks at the data - this form is used for both updates and reference.


I don't understand why the subforms would lock up, but For
sure you should not be using the form's AfterUpdate event to
do set the field. THe record has already been saved by the
time the AfterUpdate event executes so you are dirtying the
record immediately after saving it, which causes it to be
saved again.

If you do not need to display this value immediately, use
the form's BeforeUpdate event instead.

If the user needs to see the change date before the record
is saved, then use the form's Dirty event.
 
Marshall Barton said:
I don't understand why the subforms would lock up, but For
sure you should not be using the form's AfterUpdate event to
do set the field. THe record has already been saved by the
time the AfterUpdate event executes so you are dirtying the
record immediately after saving it, which causes it to be
saved again.

Thanks, Marshall! I actually just fixed it another way. Instead of using
the "AfterUpdate" event to change the field, I instantiated a public boolean
variable and set it to True - then on the Close button's event I set the
DateOfChange field's value right before closing the form.

I appreciate the input!
 
Jamie said:
Thanks, Marshall! I actually just fixed it another way. Instead of using
the "AfterUpdate" event to change the field, I instantiated a public boolean
variable and set it to True - then on the Close button's event I set the
DateOfChange field's value right before closing the form.


That will only work if the user is required to close the
form after editing a record and I'm not sure there's a way
to enforce that if the form's record source query returns
more than one record. The form's Before Update event is
simpler, more robust and the preferred approach.
 
Marshall Barton said:
That will only work if the user is required to close the
form after editing a record and I'm not sure there's a way
to enforce that if the form's record source query returns
more than one record. The form's Before Update event is
simpler, more robust and the preferred approach.

I see your point. Even though, in this particular case, the form only
returns one record, your method is still much better. Thanks!
 
Back
Top