Partial Record Deletion

Z

zyus

I hv following field & record

KPNum
--------
A1234
RF\3245
WEJ-123

Q: How to delete the alpha & character leaving only numbers?

TQ
 
S

Stefan Hoffmann

hi,
KPNum
--------
A1234
RF\3245
WEJ-123
Q: How to delete the alpha & character leaving only numbers?
Where do you get such bad data?

Aircode, place it in a standard module:

Public Function StripAlpha(AString As Variant) As Variant

Dim Count As Long
Dim Result As Variant
Dim Source As String

If IsNull(AString) Then
Result = Null
Else
Source = CStr(AString)
Result = ""
For Count = 1 To Len(Source)
Select Mid(Source, Count, 1)
Case 'A' To 'Z', 'a' To 'z'
Result = Result & Mid(Source, Count, 1)
End Select
Next Count
End If
StripAlpha = Result

End Sub

Use it in an update query: =StripAlpha([KPNum])


mfG
--> stefan <--
 
Z

zyus

I've tried but got this "syntax error" on this line

Select Mid(Source, Count, 1)

TQ

Stefan Hoffmann said:
hi,
KPNum
--------
A1234
RF\3245
WEJ-123
Q: How to delete the alpha & character leaving only numbers?
Where do you get such bad data?

Aircode, place it in a standard module:

Public Function StripAlpha(AString As Variant) As Variant

Dim Count As Long
Dim Result As Variant
Dim Source As String

If IsNull(AString) Then
Result = Null
Else
Source = CStr(AString)
Result = ""
For Count = 1 To Len(Source)
Select Mid(Source, Count, 1)
Case 'A' To 'Z', 'a' To 'z'
Result = Result & Mid(Source, Count, 1)
End Select
Next Count
End If
StripAlpha = Result

End Sub

Use it in an update query: =StripAlpha([KPNum])


mfG
--> stefan <--
 
Z

zyus

Hi,

Another syntax error on this line

Case 'A' To 'Z', 'a' To 'z'

Thanks for your response
 
S

Stefan Hoffmann

hi,
Another syntax error on this line

Case 'A' To 'Z', 'a' To 'z'
In VB(A) only double quotes are allowed as string delimiters. So use:
Case "A" To "Z"

btw, I forgot that string comparision is per default case insensitive.
So you don't need the "a" To "z" part.


mfG
--> stefan <--
 

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

Similar Threads

Query Number Of Character 3
Top 20 1
COPY RECORD 3
Convert Text Into Month 2
Data Patch By Batch 1
Query Data With.... 3
Problem with chart 1
Null Value Query 1

Top