I've a simple form, with two fields : one is an unbound combo (named unbClaimDecision) with a Value List of Yes, No, and To be decided. The other is a bound combo (named InvalidClaim_Reason). Attached to the Before_Update event of the form, I have the VBA code below. It seems to be working up to a point, but somehow when I enter a claim decision of No, I get a message about the missing reason......but when I click on Ok, the form closes anyway (without letting me enter the reason).
Can anyone help with this, please ?
Private Sub Form_BeforeUpdate(Cancel As Integer)
'Check that required fields are populated
Dim strIncompleteRecord As String
'Claim decision combo
If (IsNull(Me.unbClaimDecision) Or Me.unbClaimDecision = "") Then
Me.unbClaimDecision.BackColor = vbRed
strIncompleteRecord = strIncompleteRecord & Space(3) & Chr(149) & Space(3) & "Claim valid ?"
Else
Me.unbClaimDecision.BackColor = vbWhite
End If
'Invalid claim reason
If Me.unbClaimDecision = "No" And (IsNull(Me.InvalidClaim_Reason) Or (Me.InvalidClaim_Reason = "")) Then
Me.InvalidClaim_Reason.BackColor = vbRed
strIncompleteRecord = strIncompleteRecord & Space(3) & Chr(149) & Space(3) & "Reason for deciding that claim is invalid"
Else
Me.InvalidClaim_Reason.BackColor = vbWhite
End If
If Len(strIncompleteRecord) > 0 Then
'Raise message and prevent record update until required fields are populated
strIncompleteRecord = "The record is incomplete. Please enter all of the required fields (marked in red)." & vbCrLf & vbCrLf & strIncompleteRecord
MsgBox strIncompleteRecord, vbInformation, "Record is incomplete"
Cancel = True
End If
End Sub
Can anyone help with this, please ?
Private Sub Form_BeforeUpdate(Cancel As Integer)
'Check that required fields are populated
Dim strIncompleteRecord As String
'Claim decision combo
If (IsNull(Me.unbClaimDecision) Or Me.unbClaimDecision = "") Then
Me.unbClaimDecision.BackColor = vbRed
strIncompleteRecord = strIncompleteRecord & Space(3) & Chr(149) & Space(3) & "Claim valid ?"
Else
Me.unbClaimDecision.BackColor = vbWhite
End If
'Invalid claim reason
If Me.unbClaimDecision = "No" And (IsNull(Me.InvalidClaim_Reason) Or (Me.InvalidClaim_Reason = "")) Then
Me.InvalidClaim_Reason.BackColor = vbRed
strIncompleteRecord = strIncompleteRecord & Space(3) & Chr(149) & Space(3) & "Reason for deciding that claim is invalid"
Else
Me.InvalidClaim_Reason.BackColor = vbWhite
End If
If Len(strIncompleteRecord) > 0 Then
'Raise message and prevent record update until required fields are populated
strIncompleteRecord = "The record is incomplete. Please enter all of the required fields (marked in red)." & vbCrLf & vbCrLf & strIncompleteRecord
MsgBox strIncompleteRecord, vbInformation, "Record is incomplete"
Cancel = True
End If
End Sub