prompt before saving changes

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

Guest

hi all
i have this code:
Private Sub DIAG_BeforeUpdate(Cancel As Integer)
If Not Me.NewRecord Then
If MsgBox("Changes have been made to the Diagnosis Category" _
& vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbNo Then
Cancel = True
Me!DIAG.Undo
End If
End If
End Sub

but what i actually need is , if the field was empty before this update, not
to prompt (filling in the field for the first time).i.e.to prompt only when
the there was some data in this field and has been changed.
any one can help me with this?
 
Mybe there is a better way, but you can try this
1. Declare a variable on the form declaretion as Variant
Dim OldDIAG

2. On the OnCurrent event of the form, assign a value to the variant
OldDIAG = Me.DIAG

3. On the before update event compare the values

If Not IsNull(OldDIAG) Then
If OldDIAG <> Me.DIAG Then
If MsgBox("Changes have been made to the Diagnosis Category" _
& vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbNo Then
Cancel = True
Me!DIAG.Undo
end if
End If
end if
 
mhmaid said:
hi all
i have this code:
Private Sub DIAG_BeforeUpdate(Cancel As Integer)
If Not Me.NewRecord Then
If MsgBox("Changes have been made to the Diagnosis Category" _
& vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbNo Then
Cancel = True
Me!DIAG.Undo
End If
End If
End Sub

but what i actually need is , if the field was empty before this
update, not to prompt (filling in the field for the first
time).i.e.to prompt only when the there was some data in this field
and has been changed.
any one can help me with this?

If this is a bound control, you can check its OldValue property.
Instead of this:
If Not Me.NewRecord Then

Use this:

If Not IsNull(Me!DIAG.OldValue) Then
 
Thank your Ofer for your response.but as i am new to access , i didnt
understand step no one. hope you can explain to me this. other steps are ok.
thanks again.
 
Dirk gave you the idea how to skip no 1 and 2 stages, just put thos code on
the before update event

If Not IsNull(Me.DIAG.OldValue) Then
If Me.DIAG.OldValue <> Me.DIAG Then
If MsgBox("Changes have been made to the Diagnosis Category" _
& vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbNo Then
Cancel = True
Me!DIAG.Undo
end if
End If
end if
 
Back
Top