Form does not close on DoCmd.Close acForm, Me.Name

  • Thread starter Thread starter Chrisso
  • Start date Start date
C

Chrisso

Hi All

I have a Cancel command button on my form with this _Click event code:

Private Sub btnCancel_Click()
If Me.Dirty Then
Me.Undo
End If
DoCmd.Close acForm, Me.Name
End Sub

The trouble is when the record is dirty I have to click this button
*twice* to actually close the form. Why?!

Any ideas? Thanks in advance,
Chrisso
 
Hi Chrisso,

Often you have to hit Esc twice to entirely cancel changes to a record
on a form. Once to undo the changes to the current field and once to undo
the changes to the other fields. In case more than two are ever needed, you
could use this:

Private Sub btnCancel_Click()
Do While Me.Dirty
Me.Undo
Loop
DoCmd.Close acForm, Me.Name
End Sub

Clifford Bass
 
Back
Top