I have a form with a button that deletes the record displayed on the form and then closes the form (see the screenshot and code below). This generates an error if the Delete button is pressed before the user has entered data in any of the form fields, as the record has not yet been created. How can I modify my code so that the procedure exits in this scenario rather than executing the delete record command? In other words, the procedure needs to first check if a record is actually displayed on the form before continuing.
Code:
Private Sub btnDeleteRecord_Click()
If MsgBox("Delete this blanket order?", vbExclamation + vbYesNo + vbDefaultButton2, "Delete Contract") = vbYes Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
DoCmd.Close acForm, "frmContractDetail"
End If
End Sub