G
Gordon
I am seeking to apply form level validation for two controls in the
before update event of my form. My code looks like this:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
' An error that is special cased.
Const conErrDoCmdCancelled = 2501
On Error GoTo Err_BeforeUpdate
If IsNull(Me.cboMedium) Then
Cancel = True
strMsg = strMsg & "Medium required." & vbCrLf
End If
If IsNull(Me.cboSubject) Then
Cancel = True
strMsg = strMsg & "Subject required." & vbCrLf
End If
If Cancel Then
strMsg = strMsg & "Correct the entry, or press <Esc> to undo."
MsgBox strMsg, vbExclamation, "Invalid entry."
End If
Exit_BeforeUpdate:
Exit Sub
Err_BeforeUpdate:
' If the action was cancelled by the user for
' some reason, don't display an error message.
' Instead, resume on the next line.
If (Err = conErrDoCmdCancelled) Then
Resume Next
End If
End Sub
The first part of the validation seems to work, but when I press OK I
get the annoying error message "The DoMenutem action was canceled"
which is why I have included the error trapping code relating to error
message 2501. But this is not doing what I hoped.
Can anyone see what I am doing wrong or suggest a better way to get
rid of this redundant message.
Thanks
Gordon
before update event of my form. My code looks like this:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
' An error that is special cased.
Const conErrDoCmdCancelled = 2501
On Error GoTo Err_BeforeUpdate
If IsNull(Me.cboMedium) Then
Cancel = True
strMsg = strMsg & "Medium required." & vbCrLf
End If
If IsNull(Me.cboSubject) Then
Cancel = True
strMsg = strMsg & "Subject required." & vbCrLf
End If
If Cancel Then
strMsg = strMsg & "Correct the entry, or press <Esc> to undo."
MsgBox strMsg, vbExclamation, "Invalid entry."
End If
Exit_BeforeUpdate:
Exit Sub
Err_BeforeUpdate:
' If the action was cancelled by the user for
' some reason, don't display an error message.
' Instead, resume on the next line.
If (Err = conErrDoCmdCancelled) Then
Resume Next
End If
End Sub
The first part of the validation seems to work, but when I press OK I
get the annoying error message "The DoMenutem action was canceled"
which is why I have included the error trapping code relating to error
message 2501. But this is not doing what I hoped.
Can anyone see what I am doing wrong or suggest a better way to get
rid of this redundant message.
Thanks
Gordon