IF Statment......Again!!

  • Thread starter Thread starter Mikey May
  • Start date Start date
M

Mikey May

I want to check that the first 4 digits of a 10 digit
reference are between 0000 and 9999 but when i input the
code VB automatically changes the 0000 to 0, I have tried
using "0000" ie

If Left(AccRef, 4) > "0000" And Left(AccRef, 4) < 9999 Then
etc, etc....
, but it doesn't like it.

Also I want to check whether an Alpha character has been
used within a reference

If Left(AccRef, 1) > "a" And Left(AccRef, 1) < "z" Then,
etc, etc....

doesn't work either.

HELP!!!!

I am fairly new to VB and am finding some of the solutions
presented here a hard to follow, so as simple as poss
would be a great help.
 
Mikey May,

Left(AccRef, 4) > 0 And Left(AccRef, 4) < 9999
This should work. if the first four characters are digits (0-9), it will
return false only if they're 0000 or 9999. VBA apparently coerces the text
digits (returned by the Left function) into a number value. Or you can
ensure that it does by adding +0
If Left(AccRef, 1)+0 > 0 And Left(AccRef, 4)+0 < 9999

For your next part:
If Left(AccRef, 1) > "a" And Left(AccRef, 1) < "z"
This should work for b-y. You may have meant to use >= and <= to include a
and z.
 
Back
Top