First, I'd lose the confirmations -- very annoying. If you have problems
with users who "shouldn't" be changing data screwing things up - create
"groups" and put them in one that is datareader only.
Second, instead of Me.Undo, try using Cancel = True.
Third, "AfterUpdate" is not running because your canceling the BeforeUpdate,
and the Save that happens between the two events (BeforeUpdate - validation,
cancelable if validation fails, then the backend "save", then AfterUpdate,
to do things like refresh calced controls, etc). You have two problems
here. First, you aren't really "canceling" the validation event (but it is
stopping) because you're doing an undo instead (the effect is the same, but
it "flows" differently downstream - in effect, you're "pushing the esc
key"). The errors downstream from that are because you've messed up the
order. Like by calling AfterUpdate when there hasn't been an update, or
when the form is "dirty" because you cancelled the save. The 2115 error is
what you get if you try to requery or call AfterUpdate from BeforeUpdate.
The form is dirty until AFTER the BeforeUpdate finishes. Requery with the
form dirty calls an implicit Save, which triggers BeforeUpdate. So if you
call AfterUpdate (or Requery) from the BeforeUpdate, you call BeforeUpdate
AGAIN (form's still dirty). And if you cancel EITHER call, then the OTHER
one gets the 2115 RTE.
> 2 issues actually
> I have a subform that uses Form_BeforeUpdate to confirm user changes.
> Private Sub Form_BeforeUpdate(Cancel As Integer)
> If Me.Dirty = True Then
> If MsgBox("Data on this page has been edited." & vbCrLf & _
> vbCrLf & "Save changes?", vbYesNo, "Data Protection") = vbNo
> End If
> End If
> End Sub
> 1st issue: Form_AfterUpdate does not fire. ADP's seem to have issues
> with events not firing - I've seen this in other places - esp. when
> using a tab control.
> So fine, I'll call Form_AfterUpdate explicitly. I use this event to
> conditionally refresh/requery the parent form.
> 2nd issue (problem!):
> Any attempt at refresh/requery results in run-time error 2115 - "The
> macro or function set to the BeforeUpdate or ValidationRule property
> for this field is
> preventing <application> from saving the data in the field"
> I've tried every method of refreshing or requering the recvordset that
> I know. No luck. The new values that i want to appear onscreen are
> already in the tables, I just need the form to update.