![]() ![]() Two fragments are available in Code VBA that are used all open forms. If MsgBox("Are you sure that you want to close this form?", vbYesNo) = vbYes Then Private Sub Form_Unload(Cancel As Integer) The code below shows how to prompt the user to verify that the form should closed by using the Form_Unload event. You will notice several options are available to refine the close behaviour.Īsk the user for confirmation before closing a form Run-time error message which may even result in the user getting in your code in case saving the record is not possible for some reason such as a required field having no data.Ĭlick this to see the insertion of the close form command using Code VBA. The role of the error handling On Error GoTo HandleError etcetera is to prevent you from getting an unfriendly If you want to save records you first have to call DoCmd.RunCommand acCmdSaveRecord. Below is code commonly used in a close button on a form.ĭoCmd.Close ObjectType:=acForm, ObjectName:=Me.Name, Save:=acSavePromptĬlosing the form this way however does not save a new record or any changes you may have made. However if you want to be sure the intended form is closed it is better to be explicit. You can close the active form (or other Access object) using DoCmd.Close without any arguments. Ask the user for confirmation before closing a form. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |