1st numerical field in a string

B

Bill

Is there a VBA function that will return the
1st numerical value in a string?

E.g.,

val = FirstNo("ClassID = 8 AND bla bla bla")
val = 8
 
D

Dirk Goldgar

Bill said:
Is there a VBA function that will return the
1st numerical value in a string?

E.g.,

val = FirstNo("ClassID = 8 AND bla bla bla")
val = 8


Nope. It would be easy enough to write one, though.
 
L

Linq Adams via AccessMonster.com

The function:

Function FirstNum(StringToParse)
Dim NumVal As Integer
For i = 1 To Len(StringToParse)
If IsNumeric(Mid(StringToParse, i, 1)) Then
FirstNum = (Mid(StringToParse, i, 1))
Exit Function
End If
Next
End Function

To call it, where the field you're searching is named FieldToParse and the
field to hold the number is NumericalValue

Me.NumericalValue = FirstNum(Me.FieldToParse)

BTW, ***VAL*** is the name of an Access function and should not be used as a
variable name.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 

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

Top