How do I cancel an event from being carried out?? (1 Viewer)

Emma

Registered User.
Local time
Today, 07:10
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
 

Former

Registered User.
Local time
Today, 07:10
Joined
Oct 13, 2000
Messages
47
How about putting another If statement around the whole thing. The if asks to see whether there is anything in the COMMENTS Box.

Private Sub COMMENTS_GotFocus()

If IsNull(Me!COMMENTS) Then

If Me!Material = "other" Then
Me!COMMENTS = Me!WA_FINDTYPE
Else
.....
Endif

Else
EndIf

End Sub
 

Users who are viewing this thread

Top Bottom