When form closed check to see if the date is 1 or null

deb

Active Member
Joined
Feb 1, 2003
Messages
400
I have a form with subform.
When the user clicks to close form, check to see if the date field is left
as a 1 or null
If it is 1 or null, prompt to make sure they want to exit without choosing
date.

My below code is not working. Any suggestions?

Private Sub Form_Close()
On Error GoTo Err_FormClose
If IsNull(Me.ReportDtID) Or Me.ReportDtID = 1 Or Me.ReportDtID = "Enter
Date" Then
Me.AllowEdits = True
Forms!f2CustImpactsEdit.Form!f2CustImpactsEditDetails.Form.AllowEdits =
True
Me.AllowDeletions = True

Forms!f2CustImpactsEdit.Form!f2CustImpactsEditDetails.Form.AllowDeletions =
True

Msg = "Are you sure you want to close without choosing a date? This will
delete the record."
Ans = MsgBox(Msg, vbYesNo)

If Ans = vbNo Then
MsgBox "The Customer Impact has NOT been deleted. Choose date and close form"
Exit Sub
Else
Me.Undo
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

End If
End If
exit_Form_Close:
Exit Sub

Err_Form_Close:
MsgBox Err.Description
Resume exit_Form_Close
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

deb

Active Member
Joined
Feb 1, 2003
Messages
400
I figured it out...
Private Sub Form_Unload(Cancel As Integer)

If IsNull(Me.ReportDtID) Or Me.ReportDtID = 1 Or Me.ReportDtID = "Enter Date" Then
Me.AllowEdits = True
Forms!f2CustImpactsEdit.Form!f2CustImpactsEditDetails.Form.AllowEdits = True
Me.AllowDeletions = True
Forms!f2CustImpactsEdit.Form!f2CustImpactsEditDetails.Form.AllowDeletions = True

Msg = "You have not entered a report date? If you close now, this Customer Impact will NOT be saved. Do you want to close?"
Ans = MsgBox(Msg, vbYesNo)

If Ans = vbNo Then
MsgBox "Please, choose Report Date."
Cancel = True

Else
Me.Undo
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End If
End If
Exit Sub

End Sub
 

Forum statistics

Threads
1,181,648
Messages
5,931,212
Members
436,784
Latest member
amuljono

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top