How do I cancel an event from being carried out??

Emma

Registered User.
Local time
Today, 20:24
Joined
May 11, 2000
Messages
37
Hello!

I have a small piece of code, which when the user selects a value from a drop down list (field A), if that value is "other", the information from another list (field B)is pasted in the comments box when the comments box gets the focus. They can then add any further information into the comments box if need.

However, if the user then goes back to the comments box later to add some more info to the comments box, the value from the field b is pasted into the comments box again, therefore loosing any of the additional information they may have entered originally.

My code is:

Private Sub COMMENTS_GotFocus()
If Me!MATERIAL = "other" Then
Me!COMMENTS = Me!WA_FINDTYPE
ElseIf Me!MATERIAL = "metal" Then
Me!COMMENTS = Me!WA_FINDTYPE
ElseIf Me!COMMENTS = Not Null Then
DoCmd.cancel event '(something wrong here!!)
Else
End If
End Sub

Basically, how do I prevent the code from running if the comments box has information in it? I thought that the not null - cancel event would work but it doesnt!

I am a pretty novice VBA type, so please any help would be gratefully received!!

Many thanks
 
There is no "Cancel!"-command for the "GotFocus"-event. Sorry...

But there is one for the event OnExit like FieldA_Exit(Cancel as Integer)) or for BeforeUpdate. Just use an other event!

But: be careful! The line
ElseIf Me!COMMENTS = Not Null Then
will always be false, because any expression conatining anywhere NULL is always false!! Use instead:
ElseIf not(isnull(Me!COMMENTS)) Then

Mic
 
many thanks mic, I moved the event to "OnExit" of field A and it works perfectly!

Emma
 

Users who are viewing this thread

Back
Top Bottom