Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    DaveT is offline Access Developer
    Windows 7 Access 2010 (version 14.0)
    Join Date
    May 2010
    Location
    Texas
    Posts
    69
    Yes ....and No. I tested (briefly) just looking for "x" and it seemed to work OK for Ext, Ex, or X because the code then starts looking for a sequence of numbers following the occurrence of "x". If it finds a number, then it extracts every following number until it finds a non-numeric character. Then it stops.

    Anyway, I will look at the code and change the logic to extract an extension when it finds ANY single text character (A-Z). THis would assume that any character, a-z, that occurs will be followed by an extension. It would not be triggered by parens () or dashes or slashes, etc: only a-z.

    It would be helpful to know what cases we are dealing with.

    QUESTION: Do you have the case of Ext 111 (972) 555-5555? That is, the extension occurs before the number.

    OR, is it the rule that entensions may, or may not, be present, and if present, the extension will occur after the main number?



    In other words to write an extraction routine we have to know the patterns we are dealing with.

  2. #17
    DetrieZ is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    17
    Hey Dave!

    extract an extension when it finds ANY single text character (A-Z). THis would assume that any character, a-z, that occurs will be followed by an extension. It would not be triggered by parens () or dashes or slashes, etc: only a-z.
    A-Z. a-z is exactly right... special characters should not trigger.

    The rule is in fact .... that extensions may, or may not, be present, and if present, the extension will occur after the main number?

  3. #18
    DaveT is offline Access Developer
    Windows 7 Access 2010 (version 14.0)
    Join Date
    May 2010
    Location
    Texas
    Posts
    69
    OK, try this.

    <code>
    Public Function ExtractNumeric(TextString As String, EP As String) As String
    'version 1.1 DLT
    'pass string such as 999-555-1111 Ext 123 (with or without Ext present)
    'pass "E" or "P"
    'if E then return extension: 123
    'if P then return phone: 9995551111

    Dim a
    Dim x As Long
    Dim sDigit As String
    Const ABC As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    Dim strNumber As String
    Dim strExt As String
    Dim zPos As Long
    Dim zLEN As Long
    Dim zMAX As Long
    Dim blnFound As Boolean

    ExtractNumeric = vbNullString

    zLEN = Len(Nz(TextString))

    If zLEN = 0 Then
    Exit Function
    End If

    'if we find any character in ABC then
    'we will try to extract an extension
    'as being the next series of numbers found
    zPos = 0

    For x = 1 To zLEN
    a = Mid(TextString, x, 1)

    If InStr(ABC, a) > 0 Then
    zPos = x
    Exit For
    End If

    Next

    Select Case EP
    Case "E"

    If (zPos > 0) And (zPos < zLEN) Then
    blnFound = False

    For x = zPos To zLEN
    sDigit = Mid(TextString, x, 1)

    If IsNumeric(sDigit) Then

    blnFound = True
    ExtractNumeric = ExtractNumeric & sDigit

    ElseIf (blnFound) And Not IsNumeric(sDigit) Then
    Exit Function

    End If
    Next
    End If

    Case "P"

    If zPos > 0 Then
    zMAX = zPos
    Else
    zMAX = zLEN
    End If

    For x = 1 To zMAX
    sDigit = Mid(TextString, x, 1)

    If IsNumeric(sDigit) Then
    ExtractNumeric = ExtractNumeric & sDigit
    End If
    Next
    End Select
    End Function
    </code>

  4. #19
    DaveT is offline Access Developer
    Windows 7 Access 2010 (version 14.0)
    Join Date
    May 2010
    Location
    Texas
    Posts
    69
    One final tweak:
    ......
    'version 1.1a DLT
    ....
    Dim blnFound As Boolean
    On Error Resume Next 'no harm, no foul
    ExtractNumeric = vbNullString

  5. #20
    DetrieZ is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    17

    Resolved

    Dave... That did it.. Everything Tested OK...

    I was trying to work thru the Const abc.. but couldn't get there.

    Thank you sincerely for staying with me on this.

    Try to enjoy your weekend

    Detrie

  6. #21
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    Great work people. Is this thread ready to be marked as Solved?

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Saving Module Code to Text Files
    By ioMatt in forum Modules
    Replies: 2
    Last Post: 07-02-2011, 08:18 AM
  2. Including two queries in one report
    By kulanga in forum Reports
    Replies: 1
    Last Post: 03-23-2010, 10:21 PM
  3. What is wrong with this code?
    By nkenney in forum Forms
    Replies: 2
    Last Post: 11-16-2009, 03:04 PM
  4. Query including Null relationship?
    By David Criniti in forum Database Design
    Replies: 0
    Last Post: 08-14-2009, 09:10 PM
  5. Anything wrong with this one line of code?
    By alsoto in forum Reports
    Replies: 3
    Last Post: 07-01-2009, 09:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums