Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

NOT Operator

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Drake - 07 Feb 2005 20:12 GMT
Hi again -

I am trying to use the NOT operator to perform an action if it finds that
text in a certain cell is different than stated.  What am I doing wrong?

--------------------------

If ComboTest.Value = "Test1" And _
   rcell1.Text = Not "Test1" Then

  MsgBox "Wrong!"
Greg Maxey - 07 Feb 2005 20:38 GMT
Drake,

I don't think you need the NOT operator.  Try:

If ComboTest.Value = "Test1" And rcell1.Text <> "Test1" Then
MsgBox "Wrong!"

I tested the follwing in a Word table and it worked fine:

Sub Test()

Dim oTbl As Table
Set oTbl = ActiveDocument.Tables(1)

If Left(oTbl.Cell(1, 1).Range, Len(oTbl.Cell(1, 1).Range) - 2) _
  = "Test1" And _
  Left(oTbl.Cell(1, 2).Range, Len(oTbl.Cell(1, 2).Range) - 2) _
  <> "Test1" Then

MsgBox "Wrong"

End If

End Sub

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> Hi again -
>
[quoted text clipped - 8 lines]
>
>   MsgBox "Wrong!"
Drake - 08 Feb 2005 04:45 GMT
Greg -

this is perfect!  Thank you!

> Drake,
>
[quoted text clipped - 33 lines]
>>
>>   MsgBox "Wrong!"
Drake - 10 Feb 2005 21:15 GMT
Greg,

I am getting a  Code 424 Error - Object Required.   I think I did exactly as
you specified.  It appeared to work when the text was one word only, but it
is having problems with the multiple words.  Any thoughts?
------------------
Dim oTbl As Table
Set oTbl = ActiveDocument.Tables(2)

Combobox.Value = "test1" And _
   Left(oTbl.Cell(1, 4).Range, Len(oTbl.Cell(1,4).Range) - 2) <> "This is
another test" Or _

Combobox.Value = "test2" And _
   Left(oTbl.Cell(1, 4).Range, Len(oTbl.Cell(1,4).Range) - 2) <> "This is
another test 2" Or _
------------

> Drake,
>
[quoted text clipped - 33 lines]
> >
> >   MsgBox "Wrong!"
Greg - 10 Feb 2005 21:47 GMT
Drake,

The only thing obvious is that you code appears to be missing the "IF"
condition.

I don't have a document with a Combobox so it is hard to help figure
out what might be going on.

Sorry.
Drake - 10 Feb 2005 21:51 GMT
Okay - did some more testing and was able to get beyond the error.  Now, it
just keeps acting as if the two don't match, even when they do.
> Drake,
>
[quoted text clipped - 5 lines]
>
> Sorry.
Drake - 10 Feb 2005 22:20 GMT
Disregard!  I think I've got it!  Thanks.
> Drake,
>
[quoted text clipped - 5 lines]
>
> Sorry.
Jezebel - 07 Feb 2005 21:17 GMT
NOT is a unary operator that returns the logical opposite of what follows.
Its argument must be something that VBA can evaluate as a boolean (ie a
logical value or a number) and the result is always a boolean. You could use

If ComboTest.Value = "Test1" And Not rcell1.Text = "Test1" then ....

because (rcell1.Text = "Test1") evaluates to true or false.

But Greg's suggestion is better.

> Hi again -
>
[quoted text clipped - 7 lines]
>
>   MsgBox "Wrong!"
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.