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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
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
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

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
Back
Top