Results 1 to 5 of 5
  1. #1
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134

    vba access Comparing two strings; Recordset with string

    Hi,



    I am trying to compare a recordset saved as a string with another string...

    Code:
        If Right(Trim(rs![Company_Street]), 6) = "street" Then   ' like
            rs![Company_Street] = Replace(rs![Company_Street], "street", "str.")
        End If
            
        If Right(Trim(rs![Company_Street]), 6) = "Street" Then    'like
            rs![Company_Street] = Replace(rs![Company_Street], "Street", "Str.")
        End If
    The problem is: Mainstreet and Main Street are equal when comparing.... and that is not the case...

    An idea how to solve this... I tried "like" but it did not work.

    I also tried to do a Select Case Statement...

    Code:
    Select Case rs![Company_Street]
         
         Case Is = Right(Trim(rs![Company_Street]), 6) = "street"          
                 rs("Company_Street") = Replace(rs![Company_Street], "street", "str.")
    
          ....
          ....
    
    End Select
    But it did not work!

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    welcome to the world of string comparison. This is why google has 013620478120348710238 servers and tons of computing power. The short answer here is that you are not going to be able to run a foolproof algorithm on your data with the computing power of access.

    Another example would be something more arcane like

    Water Street
    Waterstreet Ave

    so you can't even search for 'street' and replace it effectively

    You could conceivably try to convert all instances of 'street' to str. but you would have to insert a space (" ") at the front of the string to force a break where one does not exist (as in your example) then replace all double spaces with single spaces to account for a forced space in strings that actually had them (replace(string, " ", " "))

    then you'd have to do the same thing for st, st. but then how would you account for something like 1st Street you'd end up with something like 1 str. str.

    I have yet to see an effective string parser for addresses built in access.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Susy,

    Not sure where you are located or what you real needs are, but for street types and abbreviations in Canada (or other)
    see this guide from Canada Post.


    Good luck

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    So that above code works except for values that do not have space before street? And as repeare said, if you data is not all standardized, any compare/replace will be risky. Make sure you have a backup of your data table before trying anything.

    Maybe do a query and search for values that are like MainStreat and if not many, clean up beforehand. Something like

    x: Mid(rs![Company_Street], Instr(1, rs![Company_Street], "street")-1, 1)

    In criteria box of that field put <> " "

  5. #5
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134
    Wow, I need to test all these.... but why is Main Street equal to Main street?

    thank you, for now ��

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 01-06-2016, 12:47 PM
  2. Replies: 3
    Last Post: 07-26-2012, 03:09 PM
  3. Comparing Strings
    By Paul H in forum Programming
    Replies: 1
    Last Post: 01-27-2012, 01:46 PM
  4. Comparing Two strings issue
    By ganeshvenkatram in forum Access
    Replies: 2
    Last Post: 06-16-2011, 05:27 AM
  5. Replies: 1
    Last Post: 07-31-2009, 03:57 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