Why is Cancel Ignored?

C

Chuck

I have a situation where two fields (both Combo Boxes in this case) are
optional if neither is used and required if either is used; i.e., if either
one is used they must both be used. The Form BeforeUpdate property is
'=CrossCheckKeys(0)'. The CrossCheckKeys function is:

Function CrossCheckKeys(Cancel As Integer)
Dim CurrForm As Form: Set CurrForm = Screen.ActiveForm With CurrForm
If (IsNull(.Controls("comSinkKey")) And Not IsNull(.Controls("comSrceKey"))) _
Or (IsNull(.Controls("comSrceKey")) And Not IsNull(.Controls("comSinkKey")))
Then
If IsNull(.Controls("SinkKey")) Then
MsgRtn "DYN003", "Sink", "Source"
Else
MsgRtn "DYN003", "Source", "Sink"
End If 'IsNull(.Controls("SinkKey"))
Cancel = True
Else
BeforeFormUpdate
End If '(.Controls("SinkForm") = "" And .Controls("SrceForm") <>
"") _ ...
End With 'CurrForm
End Function

The CrossCheckKeys code does exactly what I want when one key has a value
and the other is null except that Cancel seems to be ignored. It is being
set to -1 when appropriate but the bad record is still written to the
database.

I tried putting an [Event Procedure] between the Before Update property and
the CrossCheckKeys function but the result was the same.

Thank you in advance for any suggestions.
 
A

Allen Browne

The property doesn't have the Cancel argument.

Set the form's BeforeUpdate property to:
[Event Procedure]
Then click the Build button (...) beside the property.
Access opens the code window.
Enter:
Call CrossCheckKeys(Cancel)

Alternatively, use the CancelEvent action, though this is not as good a
solution.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top