Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 40
  1. #16
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    And you'll need to turn as long into as string if you wish to use *like which is a text command.




    Sent from my iPhone using Tapatalk

  2. #17
    NadiaVKhan is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    25
    Sorry. Its supposed to be just "phone"

    There is actually note a <dot> there. Thats just poor picture editing

  3. #18
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    Eh? So are you good to go now?

  4. #19
    NadiaVKhan is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    25
    I changed

    Code:
    Public Function GetNumbers(strIn As String) As Long
    Dim i As Integer
    Dim strNum As String
    
    On Error GoTo num_err
    
    For i = 1 To Len(strIn)
    If IsNumeric(Mid(strIn, i, 1)) Then
    strNum = strNum & Mid(strIn, i, 1)
    End If
    Next
    
    GetNumbers = CLng(strNum)
    Exit Function
    
    num_err:
    GetNumbers = -1
    
    End Function

    To

    Code:
    Public Function GetNumbers(strIn As String) As String
    Dim i As Integer
    Dim strNum As String
    
    On Error GoTo num_err
    
    For i = 1 To Len(strIn)
    If IsNumeric(Mid(strIn, i, 1)) Then
    strNum = strNum & Mid(strIn, i, 1)
    End If
    Next
    
    GetNumbers = CLng(strNum)
    Exit Function
    
    num_err:
    GetNumbers = -1
    
    End Function
    Though I am still getting the same error

  5. #20
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    When you changed the return to be a String, you should have also changed the line just before Exit Function from CLng(strNum) to just strNum. Here is the function revised:
    Code:
    Public Function GetNumbers(strIn As String) As String
        Dim i As Integer
        Dim strNum As String
        
        On Error GoTo GetNumbers_Error
        
        For i = 1 To Len(strIn)
            If IsNumeric(Mid(strIn, i, 1)) Then
                strNum = strNum & Mid(strIn, i, 1)
            End If
        Next
        
        GetNumbers = strNum
        
    GetNumbers_Exit:
        Exit Function
        
    GetNumbers_Error:
        Call MsgBox("Error parsing value '" & strIn & "'." & vbCrLf & "Error: " & Err & " - " & Err.Description, vbOKOnly, "GetNumbers():")
        GetNumbers = ""
        Resume GetNumbers_Exit
    End Function

  6. #21
    NadiaVKhan is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    25
    Thanks. But I get the same error when I try searching for a number in my query

  7. #22
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    What error message are you getting?

  8. #23
    NadiaVKhan is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    25
    Sorry!! I thought I had entered it.

    "Data type mismatch in criteria expression"
    Click image for larger version. 

Name:	1.png 
Views:	8 
Size:	13.5 KB 
ID:	28098

    I used

    Code:
    Option Compare Database
    Option Explicit
    
    Public Function GetNumbers(strIn As String) As String
        Dim i As Integer
        Dim strNum As String
        
        On Error GoTo GetNumbers_Error
        
        For i = 1 To Len(strIn)
            If IsNumeric(Mid(strIn, i, 1)) Then
                strNum = strNum & Mid(strIn, i, 1)
            End If
        Next
        
        GetNumbers = strNum
        
    GetNumbers_Exit:
        Exit Function
        
    GetNumbers_Error:
        Call MsgBox("Error parsing value '" & strIn & "'." & vbCrLf & "Error: " & Err & " - " & Err.Description, vbOKOnly, "GetNumbers():")
        GetNumbers = ""
        Resume GetNumbers_Exit
    End Function

  9. #24
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Test to see if doing that in the query even works. Look in your table for an exact value and put that in the Criteria box in the query as a text (with quotes around it) or as a number (without quotes) and see what works. Leave off the Like part and just do the specific value.

  10. #25
    NadiaVKhan is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    25
    Hmm.. The query does not work when I remove the LIKE, have quotes, or have no quotes. It will work if I remove the Expr1: GetNumbers([Home Phone]). But thats the whole point.

  11. #26
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051

    Make Query Ignore Special Characters

    Initially I'd be tempted to add debug.print strnum just before getnumbers =strnum.

    You can then at least see what is being produced by the function in the immediate window.

    I should add remover the whole condition too for this test

    I'd also like to know the field type of [home number]



    Sent from my iPhone using Tapatalk

  12. #27
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Or take out the Criteria for that field altogether, does it return the correct numeric digits in that field?

  13. #28
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Expr1:getnumbers(Cstr([Home Phone]))

  14. #29
    NadiaVKhan is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    25
    1. When I run the query without any criteria, I am returned "#Error", "1" (a single digit), or a full number with no special characters (ie: 5550403945).

    A. The reason I am receiving single digits is in part due to those Cases of mine which include more than one individual, and thus, more than one phonenumber. For example, If I have 5 individuals attached to one case, Expr1 will return "Case# / Name / 1" & "Case# / Name 2" & "Case# / Name 3" & "Case# / Name 4" & "Case# / Name 5".




    2. The data type of [Home Number] as listed in the design view of the table is "short text"

    3. I also tried "Expr1:getnumbers(Cstr([Home Phone]))". But that did not make a diffeerence

  15. #30
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Are you saying home number can have more than one phone number per line in the table.

    I thought it only contained 1 phone number and nothing else in the phone number field.


    Sent from my iPhone using Tapatalk

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

Similar Threads

  1. Using Replace() for special characters
    By RayMilhon in forum Programming
    Replies: 2
    Last Post: 01-07-2017, 02:44 PM
  2. Special Delimiter characters
    By cliff.clayman in forum Import/Export Data
    Replies: 12
    Last Post: 09-13-2016, 10:52 AM
  3. Replies: 1
    Last Post: 07-22-2015, 08:11 AM
  4. Special characters in Default Value and Query
    By blacksaibot in forum Queries
    Replies: 1
    Last Post: 03-07-2012, 10:36 AM
  5. Special Characters
    By orgelizer in forum Access
    Replies: 0
    Last Post: 03-20-2007, 08:24 PM

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