Full Version: "Not Like" operator in VBA
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
WongMeister
I'm taking my first stab in creating a complex function.

In this part of the code, I have:

If Mid(Mod1, 1, 1) Like "[A-Z]" Then....

But if I want this to change to the exclusion, I get an error message:

If Mid(Mod1, 1, 1) Not Like "[A-Z]" Then...

Does the word "Not" not work when creating a vba function?
JeffK
You have to do it a bit differently in VBA than in SQL. VBA recognizes Like as an operator but you have to negate the whole expression rather than the operator.

For example, change this:
If Mid(Mod1, 1, 1) Not Like "[A-Z]" Then...

To this:
If Not (Mid(Mod1, 1, 1) Like "[A-Z]") Then...

Note the placement of the Not operator before the entire Like comparison.

HTH
Jeff
WongMeister
Thanks Jeff!

As my short-term memory begins to fade in my adult life, I find it more difficult to remember the specific nuances betwen SQL and VBA...

Thanks again,
Rich
JeffK
Happy to help. Good luck with the rest of your "first stab"! sad.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.