Good afternoon everyone. My problem is the following:
I have an input bounded form which i use to create new projects. In this form there are some mandatory fields which need to be filled if the user want to save the record (managed by Before Updating event). In the same form i have a button to close and save data (i know it is not necessary but user want to have it to close the form).
At the moment i press the
Close Button (the code in the button is simple
docmd.close) the system, trough the Before Updating event:
- ask if i want to save the record;
- if answer is NO, close the form without save;
- if the answer is Yes, it control if all mandatory fields are filled and if some mandatory fields are not filled, it gives a message with the field name to be filled.
At this point, my problem: since I'm in the "Close Button" event, it close ANYWAY the form while i would like it remain open to fill the missing information.
Below is my Before update code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If MsgBox("Do you want to save the changes for this record?", _
vbYesNo + vbQuestion, "Save Changes?") = vbNo Then
Cancel = True
Me.Undo
Else
vMsg = ""
Select Case True
Case IsNull(Me.RAMZ_ID)
vMsg = "RAMZ ID is missing"
Case IsNull(Me.Project_Name)
vMsg = "Project Name is missing"
Case IsNull(Me.Department)
vMsg = "Department is missing"
..............
End Select
If vMsg <> "" Then
Cancel = True
MsgBox vMsg, vbCritical, kREQD
End If
End If
End Sub
I tried to check in the group, but it seams i didn't find what i need. Probably it is something simple to be added at the close event but i cannot understand how to manage.
Thanks for any suggestion.
Cheers.