if first digit of a WO is A or to Z...then substract first 5 digit

L

ldiaz

this code works perfect if the first digit is "D" but how I make it works
with any
letter, example from A to Z?

If Left([ScanWO], 1) = "D" Then
WOnumber = Left([ScanWO], 5)
Else
WOnumber = Left([ScanWO], 6)
End If


Thanks
 
B

BruceM

I can't see how this would work. If the first character is D you extract
the leftmost five characters, which include the D. However, if ScanWO is
always six characters you could use the Right function:

If Asc(Left([ScanWO], 1)) >= 65 And _
Asc(Left([ScanWO], 1)) <=90 Then
WOnumber = Right([ScanWO], 5)
Else
WOnumber = [ScanWO]
End If

If the first character could be a lower case letter the code will need to be
expanded to accomodate that. See Help for more information about the Asc
function. Also see Help about the Chr function, which can be used to
determine the number to be used with the Asc function.

If the other option (other than an upper case letter) for the first
character is a number you could use:

If Asc(Left([ScanWO], 1)) >= 65 Then
WOnumber = Right([ScanWO], 5)
Else
WOnumber = [ScanWO]
End If

If there is a variable number of characters, none of the above will work
reliably. In that case you will need to provide more information about what
exactly you need to do.

BTW, in the future you should use the Subject line for just the subject of
the question. Post the question in the message body.
 
L

ldiaz

thanks Bruce,

the code works fine..

Thanks again.
--
Lorenzo Díaz
Cad Technician


BruceM said:
I can't see how this would work. If the first character is D you extract
the leftmost five characters, which include the D. However, if ScanWO is
always six characters you could use the Right function:

If Asc(Left([ScanWO], 1)) >= 65 And _
Asc(Left([ScanWO], 1)) <=90 Then
WOnumber = Right([ScanWO], 5)
Else
WOnumber = [ScanWO]
End If

If the first character could be a lower case letter the code will need to be
expanded to accomodate that. See Help for more information about the Asc
function. Also see Help about the Chr function, which can be used to
determine the number to be used with the Asc function.

If the other option (other than an upper case letter) for the first
character is a number you could use:

If Asc(Left([ScanWO], 1)) >= 65 Then
WOnumber = Right([ScanWO], 5)
Else
WOnumber = [ScanWO]
End If

If there is a variable number of characters, none of the above will work
reliably. In that case you will need to provide more information about what
exactly you need to do.

BTW, in the future you should use the Subject line for just the subject of
the question. Post the question in the message body.

ldiaz said:
this code works perfect if the first digit is "D" but how I make it works
with any
letter, example from A to Z?

If Left([ScanWO], 1) = "D" Then
WOnumber = Left([ScanWO], 5)
Else
WOnumber = Left([ScanWO], 6)
End If


Thanks
 
A

a a r o n _ k e m p f

you would want to put that constraint on a custom data type-- in SQL
Server.
use a rule to enforce the constraint-- in one place-- and then reuse
it everywhere.

_Aaron
 
Top