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

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
 
C

Clifford Bass

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top