vincem1099
asked on
Closing Form from After Update Event
I have a form that is to close after collecting data in a single field. I put a DoCmd.Close command in the after update event which works well if the field is updated and the enter button is pressed, however if the field is updated and the form close button is selected I get the error message 'Error 2501: The Close action was canceled'. There is code running in the close event to update the parent form. How do I correct this error message? Attached is the code related to this form.
Private Sub FMS_Oblig_AfterUpdate()
'Close Form
DoCmd.Close acForm, "Change Obligation"
End Sub
Private Sub Form_Close()
Dim rst, rst2 As Recordset
Dim strBookmark As Variant
Dim strFCPParameter As String
'Move active record back to same location with updated data
If Me.OpenArgs Then
Forms("Multi Year End").List_of_Year_End_Multi_Year_Obligations.Requery
Set rst = Forms("Multi Year End").List_of_Year_End_Multi_Year_Obligations.Form.RecordsetClone
Set rst2 = Me.RecordsetClone
strFCPParameter = IIf(IsNull(rst2.Fields("FCP")), " AND (FCP) Is Null", " AND (FCP='" & rst2.Fields("FCP").Value & "')")
rst.FindFirst "(ACC='" & rst2.Fields("ACC").Value & "') AND (Appropriation='" & rst2.Fields("Appropriation").Value & "') AND ([As Of]=#" & rst2.Fields("As Of").Value & "#)" & strFCPParameter
Forms("Multi Year End").List_of_Year_End_Multi_Year_Obligations.Form.Bookmark = rst.Bookmark
Else
Forms("Last Year End").Last_Year_End_Obligations.Requery
Set rst = Forms("Last Year End").Last_Year_End_Obligations.Form.RecordsetClone
Set rst2 = Me.RecordsetClone
strFCPParameter = IIf(IsNull(rst2.Fields("FCP")), " AND (FCP) Is Null", " AND (FCP='" & rst2.Fields("FCP").Value & "')")
rst.FindFirst "(ACC='" & rst2.Fields("ACC").Value & "') AND (Appropriation='" & rst2.Fields("Appropriation").Value & "') AND ([As Of]=#" & rst2.Fields("As Of").Value & "#)" & strFCPParameter
Forms("Last Year End").Last_Year_End_Obligations.Form.Bookmark = rst.Bookmark
End If
Set rst = Nothing
End Sub
Why is there an Enter button if you always want to close the form after the entry is made?
ASKER
I was referring to the enter button on the keyboard. Pressing the enter button on the keyboard lets access know that the field has been updated so the after update event will trigger.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.