G
Guest
I've read numerous posts about this, but I still can't figure out what I'm
doing wrong. It's simple I'm sure, but I'm a novice at coding, so please
forgive me.
I have a form that has a date field (dtmMo). If this field is left blank
and the user tries to close the form, I want a message box to pop up telling
them that the record will be deleted (due to no date) and give them the
option to close the form and delete the record, or stop the close process and
fill in the date. Here's what I have so far:
Private Sub Form_Close()
Dim Cancel As Integer
Confirm = MsgBox("Date field is null. Continuing will cause this record
to be lost." & vbCrLf & "If you wish to continue, click OK." & vbCrLf & "If
you wish to save this record, click Cancel and enter a date.", vbOKCancel,
"Confirm")
If Confirm = vbCancel Then
Me.dtmMo.SetFocus
ElseIf Confirm = vbOK Then
DoCmd.Close acForm, "frmSummary", acSaveNo
End If
End Sub
I realize the message box pops up before checking to see if the date field
is null or not and that's one of my problems. Setting up the code this way
is the only way I could get the box to pop up at all. Also, regardless of
which button I click, Cancel or Ok, the form closes anyway.
Any help is appreciated!
doing wrong. It's simple I'm sure, but I'm a novice at coding, so please
forgive me.
I have a form that has a date field (dtmMo). If this field is left blank
and the user tries to close the form, I want a message box to pop up telling
them that the record will be deleted (due to no date) and give them the
option to close the form and delete the record, or stop the close process and
fill in the date. Here's what I have so far:
Private Sub Form_Close()
Dim Cancel As Integer
Confirm = MsgBox("Date field is null. Continuing will cause this record
to be lost." & vbCrLf & "If you wish to continue, click OK." & vbCrLf & "If
you wish to save this record, click Cancel and enter a date.", vbOKCancel,
"Confirm")
If Confirm = vbCancel Then
Me.dtmMo.SetFocus
ElseIf Confirm = vbOK Then
DoCmd.Close acForm, "frmSummary", acSaveNo
End If
End Sub
I realize the message box pops up before checking to see if the date field
is null or not and that's one of my problems. Setting up the code this way
is the only way I could get the box to pop up at all. Also, regardless of
which button I click, Cancel or Ok, the form closes anyway.
Any help is appreciated!