Can't get off record from AfterUpdate

  • Thread starter Thread starter Graeme Richardson
  • Start date Start date
G

Graeme Richardson

Hi Bob, try the code in a the Form_BeforeUpdate event. Note that update is
cancelled if criteria not met

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Nz(txtFrom) = "" Or Nz(txtTo) = "" Then
Cancel = True
MsgBox ("You must have a 'From' and 'To' filled in.")
Else
txtDist = Abs(DLookup("Distance", "Locations", "Location = '" &
Me!txtTo & "'") - _
DLookup("Distance", "Locations", "Location = '" & Me!txtFrom &
"'"))
End If
End Sub

Hope this helps, Graeme
 
I have a problem which I can't figure out. The code below works. It does
what I want it to do. The problem is that once it fires I can't get off the
record. The record stays in edit mode and I'm stuck there. However it did do
the calculation and updated the field the way I wanted.

Any clues welcomed.
Bob

Private Sub Form_AfterUpdate()
If Nz(txtFrom) = "" Or Nz(txtTo) = "" Then
MsgBox ("You must have a 'From' and 'To' filled in.")
Else
txtDist = Abs(DLookup("Distance", "Locations", "Location = '" & Me!txtTo
& "'") - _
DLookup("Distance", "Locations", "Location = '" & Me!txtFrom &
"'"))
End If
End Sub
 
Back
Top