Hello all,
I search around and came upon some code to do some of the needed items for my form when a user clicks the close button, but i ended up with a few errors or issues with it so far. Here is what I am trying to do and I will put the code below that I have been working on. On exit, I want to make sure that if a user doesn't click the save button, it will clear the form before closing and not save the new data since the whole form wasn't filled out properly. or check to see if certain fields are populated. I don't want half data saved and also I don't want it to delete records that are being updated or changed.
So basically on click of the close form, clear data that hasn't been saved and check to ensure two fields have been populated before closing and saving, prompting a user with a msg, stating Do you want to save this form or close, or cancel to go back and fill in the proper information.
Code:
Private Sub CloseRecord_Exit(Cancel As Integer)
Dim strmsg As String
On Error GoTo Err_cmdClose_Click
strmsg = "Are you sure to close Application"
If MsgBox(strmsg, vbQuestion + vbYesNo, "Close Application") = vbYes Then
If IsNull(Me.Video_Number) Or IsNull(Me.cboModemDNSName) Then
MsgBox ("Record will be not saved")
DoCmd.RunCommand acCmdUndo
End If
DoCmd.Close acForm, "Video Form"
Else
If IsNull(Me.Video_Number) Or IsNull(Me.cboModemDNSName) Then
Me.Video_Number.BorderColor = vbRed
Me.cboModemDNSName.BorderColor = vbRed
DoCmd.CancelEvent
End If
End If
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
End Sub