Access question

  • Thread starter Thread starter CalBerkleyTekkie
  • Start date Start date
C

CalBerkleyTekkie

Hopefully this will be easy for some people.

I'm trying to write an If statement in VBA for access, however I think
I am formatting it wrong. What I am logically trying to do is this: If
the first 6 numbers in this given field does not equal 000001 or
000002, then carry out the rest of the function. Currently I have it
formatted like this:

If IdentificationNumber <> 000001 Or IdentificationNumber <> 000002
Then

Any suggestions? Thanks!

-Jimmy
 
Assuming that the field is a text field (otherwise leading zeroes would be
irrelevant), try

IF Left(IdentificationNumber,6) <> "000001" AND
Left(IdentificationNumber,6) <> "000002" Then
'Do something here
End IF

Note the use of AND instead of OR. Your boolean logic would have run the
code every time. Since if the value is 000001 then it is by definition not
000002. And vice versa for 000002. And of course any other value would be
true for both parts of the if statement.
 

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

Back
Top