Can't make sense of this

  • Thread starter Thread starter TeeSee
  • Start date Start date
T

TeeSee

The immediately following is the input code .......
Do
.Edit
strA = ![MaterialDescription]
Debug.Print strA
For intI = 1 To Len(strA)
strB = Mid(strA, intI, 1)
If strB Like "[A-Z,a-z,0-9,_,(,),/,-, ]" Then
strC = strC & strB
End If
Next intI
Debug.Print strC
Exit Sub
![Description] = strC
.Update
.MoveNext
strC = vbNullString
Loop Until .EOF

And the following is the output .... before and after. Why does the
hyphen which I believe is CHR$(45) not behave like the other
characters???

MICRO-LOK AP-T 1/2"(7/8)x 1"
MICROLOK APT 1/2(7/8)x 1
 
The immediately following is the input code .......
Do
.Edit
strA = ![MaterialDescription]
Debug.Print strA
For intI = 1 To Len(strA)
strB = Mid(strA, intI, 1)
If strB Like "[A-Z,a-z,0-9,_,(,),/,-, ]" Then
strC = strC & strB
End If
Next intI
Debug.Print strC
Exit Sub
![Description] = strC
.Update
.MoveNext
strC = vbNullString
Loop Until .EOF

And the following is the output .... before and after. Why does the
hyphen which I believe is CHR$(45) not behave like the other
characters???

MICRO-LOK AP-T 1/2"(7/8)x 1"
MICROLOK APT 1/2(7/8)x 1
The hyphen is a reserved character in the regular expressions parser,
for use in delimiting a range as you have A-Z, etc, so you are
telling the computer to find any characters between the range of null
and null. since chr(450 is not between null and null, it fails.

Help says: A hyphen (-) can appear either at the beginning (after an
exclamation point if one is used) or at the end of charlist to match
itself. In any other location, the hyphen is used to identify a range
of characters.

I could not get it to work by moving the hyphen.

I'd rewrite the if statement as follows
If strB ="-" OR strB like ""[A-Z,a-z,0-9,_,(,),/, ]" Then
 
Sorry, keep confusing SQL Server syntax with ACCESS syntax:

If strB Like "[A-Za-z0-9_()/ -]" Then

or

If strB Like "[A-Za-z0-9_()/[-] ]" Then

--

Ken Snell
http://www.accessmvp.com/KDSnell/


Ken Snell said:
Try this:

If strB Like "[A-Za-z0-9[_]()/ -]" Then

--

Ken Snell
http://www.accessmvp.com/KDSnell/


TeeSee said:
The immediately following is the input code .......
Do
.Edit
strA = ![MaterialDescription]
Debug.Print strA
For intI = 1 To Len(strA)
strB = Mid(strA, intI, 1)
If strB Like "[A-Z,a-z,0-9,_,(,),/,-, ]" Then
strC = strC & strB
End If
Next intI
Debug.Print strC
Exit Sub
![Description] = strC
.Update
.MoveNext
strC = vbNullString
Loop Until .EOF

And the following is the output .... before and after. Why does the
hyphen which I believe is CHR$(45) not behave like the other
characters???

MICRO-LOK AP-T 1/2"(7/8)x 1"
MICROLOK APT 1/2(7/8)x 1
 
Back
Top