To close a subform?
A subform sits on the main form. It is not open in its own right, so you
can't "close" it. You can remove it from the main form by setting the
SourceObject property of the subform control to a zero-length string. Or you
can close the main form (so any subforms are no longer shown either.)
If by "subform" you mean another popup form you opened, you can add a
command button to that form, and set the button's Cancel property to Yes.
Whatever you put in the button's Click event procedure then executes when
you press Esc. Typically the code for the Click event would be something
like this:
If Me.Dirty Then Me.Dirty = False
DoCmd.Close acForm, Me.Name
Note: remove the first line above it the form is unbound.
It is important for a bound form, to prevent this bug:
http://allenbrowne.com/bug-01.html