Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2010
    Posts
    2

    Unanswered: Help with a function containing non number characters

    I have a function in Microsoft Access 2000 that I have obtained where it removes all of the text id's in a field that I have which I need to return only numbers for. The issue I am having is these numbers are in decimal form such as 905.83 are coming back as just 90583. I need to be able to have the decimals come through in my function. Below is the code of the function I have currently. Any ideas?

    Function fncDigitsOnly(varOldNumber As Variant) As Variant

    ' Removes any non-numeric characters in a string, returning
    ' only the numeric digits. Returns Null if argument is Null.

    Dim I As Integer
    Dim intLength As Integer
    Dim intDigits As Integer
    Dim strThisCharacter As String
    Dim strOldNumber As String
    Dim strNewNumber As String

    If IsNull(varOldNumber) Then
    fncDigitsOnly = Null
    Exit Function
    End If

    strOldNumber = varOldNumber & vbNullString
    intLength = Len(strOldNumber)
    strNewNumber = strOldNumber

    For I = 1 To intLength
    strThisCharacter = Mid$(strOldNumber, I, 1)
    Select Case Asc(strThisCharacter)
    Case 48 To 57
    intDigits = intDigits + 1
    Mid$(strNewNumber, intDigits, 1) = strThisCharacter
    End Select
    Next I

    fncDigitsOnly = Left$(strNewNumber, intDigits)

    End Function
    Last edited by OnYourSide25; 07-19-10 at 17:01.

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    My first thought would be to simply include the code for the decimal (46 I think).
    Paul

  3. #3
    Join Date
    Jul 2010
    Posts
    2
    Thanks for the help I knew it was something that it was obvious including 46 worked perfectly. Sometimes I get lost in the code.

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Happy to help, and welcome to the site by the way!
    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •