Hi
I have conditions in the Form's BEFORE UPDATE property that when met, I get the desired error message box and the OK button:
However, if this code is triggered after I click the close form button, the form closes after I click the OK button on the message, rather than remaining open so I can fix the error. This is the code behind the CLOSE button:
How can I get the Form's BEFORE UPDATE property to cancel the FORM CLOSE command in addition to giving me the error message? I'm lost!
Thanks!
Jim DeGeorge![[wavey] [wavey] [wavey]](/data/assets/smilies/wavey.gif)
I have conditions in the Form's BEFORE UPDATE property that when met, I get the desired error message box and the OK button:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
If Not IsNull([ctlDateClosed]) And ((Not IsNull(Me!ctlResolution)) Or Me!ctlResolution <> "") And [ctlGap_Status] = 1 Then
strMsg = "RESOLUTION and DATE CLOSED fields cannot be entered"
strMsg = strMsg & vbCrLf & "without changing the STATUS to CLOSED."
strMsg = strMsg & vbCrLf & "Click OK to correct."
MsgBox strMsg, 16, "Conversion Gap Analysis"
Me.Undo
Exit Sub
ElseIf Not IsNull([ctlDateClosed]) And (IsNull(Me!ctlResolution) Or Me!ctlResolution = "") And [ctlGap_Status] <> 1 Then
strMsg = "STATUS cannot be set to CLOSED"
strMsg = strMsg & vbCrLf & "and DATE CLOSED cannot be entered without"
strMsg = strMsg & vbCrLf & "entering a detailed RESOLUTION."
strMsg = strMsg & vbCrLf & "Click OK to correct."
MsgBox strMsg, 16, "Conversion Gap Analysis"
Me.Undo
Exit Sub
Else
If ctlAssessment = "" Then
Dim msg, DgDef, Response As Variant
Beep
msg = "You must enter a detailed Assessment. " _
& vbCrLf & "Click OK to try again!"
DgDef = MB_OK + MB_ICONINFORMATION + MB_DEFBUTTON2
Response = MsgBox(msg, DgDef, Title)
Me!ctlAssessment.SetFocus
DoCmd.RunCommand acCmdUndo
Exit Sub
Else
DoEvents
Exit Sub
End If
End If
End Sub
Code:
Private Sub btnClose_Click()
DoCmd.Close acForm, Me.NAME, acSaveYes
End Sub
Thanks!
Jim DeGeorge
![[wavey] [wavey] [wavey]](/data/assets/smilies/wavey.gif)