Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

return only numeric values 1

Status
Not open for further replies.

smuthcrmnl777

Technical User
Jan 16, 2006
104
US
Code:
Mid([line-sample],InStr([line-sample],'-')+1)

This code returns values to the right of the '-'.

How can I make sure that I only return numeric values and omit the letters?
 
Perhaps something like:
Code:
For i=1 to Len(strString)
   If IsNumeric(Mid(strString,i,1)) Then
      strNumString=strNumString & Mid(strString,i,1)
   End If
Next

 
To skip trailing letters:
Val(Mid([line-sample],InStr([line-sample],'-')+1))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
How would I have it in my query though?

The code is not in VBA, but in the query field.
 
Who is that question to? I guess it is easy enough to see how PHVs code works in a query, as for my snippet, you could use a function:
Code:
Function NumOnly(strString)
Dim strNumString
If IsNull(strString) Then
    Exit Function
End If
For i = 1 To Len(strString)
   If IsNumeric(Mid(strString, i, 1)) Then
      strNumString = strNumString & Mid(strString, i, 1)
   End If
Next
NumOnly = strNumString
End Function

Then in the query:
[tt]SELECT NumOnly([Field1]) FROM tblTable;[/tt]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top