You may find it better to loop backwards through Forms collection: some
collections get confused if earlier items are disappearing while the loop is
running.
There is a bug with the Close method that can cause a form to *silently*
lose the user's edits if the record can't be saved (e.g. required field
missing). To avoid that, an explicit save is needed. If the form is unbound,
it has no Dirty property, so we need to test for that first.
If that still doesn't work, it may be worth considering the situation in
which the shortcut menu is being fired. Beyond that, it may be a matter of
checking that the code works on a single basic form in another database, and
if so, tracking what is open that is preventing the close.
Suggestion to try:
Dim lng As Long
Dim frm As Form
For lng = Forms.Count -1 To 0 Step -1
Set frm = Forms(lng)
If HasProperty(frm, "Dirty") Then
If frm.Dirty Then
frm.Dirty = False
End If
End If
DoCmd.Close acForm, Forms(lng).Name, acSaveNo
Next
Set frm = Nothing
'Close anything else you opened.
'Dereference any other objects.
Application.Quit
Public Function HasProperty(obj As Object, strPropName As String) As Boolean
'Purpose: Return true if the object has the property.
Dim varDummy As Variant
On Error Resume Next
varDummy = obj.Properties(strPropName)
HasProperty = (Err.Number = 0)
End Function