Results 1 to 12 of 12
  1. #1
    wes9659 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2014
    Location
    Dover, Ohio
    Posts
    88

    Creating Proper format on Address Direction

    Ok here is another one of those brain teaser for all the VBA Experts
    Private Sub Address_AfterUpdate()
    Address = StrConv(Address, vbProperCase)
    End Sub

    I have this code to put address test in proper format which it does with one exception the Directions are not right. For example

    If I entered in
    1234 ohio st. ne. I get 1234 Ohio St Ne. I want it to read 1234 Ohio St. NE.

    My question is what would I do to allow only the exceptions of NE, SE, NW, SW, to be read in all uppercase. They always follow the address.

    Once again thanks everyone for participating and helping in this form and helping others like me.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    You might want to look at US Postal Service Guidelines before doing anything.

  3. #3
    wes9659 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2014
    Location
    Dover, Ohio
    Posts
    88
    I understand how to address a letter: the issue was making the NE, SE, SW, NW remain capitalized after setting the rest of the address to proper case format. That is what I was asking about if I was not clear. Thank you

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    This could get complicated.

    Maybe:

    Replace(Replace(Replace(Replace([Address], " Nw", " NW"), " Sw", " SW"), " Ne", " NE"), " Se", " SE")

    Issue with that is if the address has something like: 319 Seaver St, the Se will become SE.

    Otherwise, expect would need a VBA custom function.

    Another option is to have a separate field for the direction.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    The USPS deals with Directionals in Addressing Guidelines here Note The preferred format, and the unacceptable.
    Since you are automating addresses, you might want to use the preferred format. Just clarifying my comment.

  6. #6
    wes9659 is offline Advanced Beginner
    Windows 8 Access 2010 64bit
    Join Date
    Apr 2014
    Location
    Dover, Ohio
    Posts
    88
    Thanks June,
    Quick question how would I implement it?
    I added it to next line in code and got error see attached photo. Here is what I was attempting to use unsuccessfully
    Private Sub Address_AfterUpdate()
    Address = StrConv(Address, vbProperCase)
    Replace(Replace(Replace(Replace([Address], " Nw", " NW"), " Sw", " SW"), " Ne", " NE"), " Se", " SE")
    End Sub

    Thanks everyone for all the help and tremendous guidance.

    Click image for larger version. 

Name:	Screenshot 2014-09-03 16.22.54.png 
Views:	17 
Size:	38.5 KB 
ID:	18010

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    Address = Replace(Replace(Replace(Replace(StrConv(Address, vbProperCase), " Nw", " NW"), " Sw", " SW"), " Ne", " NE"), " Se", " SE")

    Remember, " Seaver" will become " SEaver" and " Neverland" will become " NEverland" and " Swiss" will become " SWiss". I doubt NW will be an issue.

    So use at your own risk, no warranty implied.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    what would I do to allow only the exceptions of NE, SE, NW, SW, to be read in all uppercase. They always follow the address.
    Here is another method:
    Code:
    Private Sub Address_AfterUpdate()
        Dim tmp As String
        Dim tmpAddress As String
        Dim sAddress As String
        Dim dot As String
        Dim Pos As Integer
    
        Me.Address = StrConv(Me.Address, vbProperCase)
        sAddress = Trim(Me.Address)
    
        'find last space
        Pos = Len(sAddress) - InStrRev(sAddress, " ")
        'check of there is a period
        dot = Right(sAddress, 1)
        If dot <> "." Then
            dot = "."
        End If
    
        tmp = Right(sAddress, Pos)
        tmp = Replace(tmp, ".", "")
        If tmp = "nw" Or tmp = "ne" Or tmp = "SW" Or tmp = "SE" Then
            tmp = UCase(tmp)
            tmpAddress = Trim(Left(sAddress, Len(sAddress) - Pos))
            Me.Address = tmpAddress & " " & tmp & dot
        End If
    
    End Sub

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    Was the dot in the address or just period at end of sentence?

    If the period is in the address (always):

    Address = Replace(Replace(Replace(Replace(StrConv(Address, vbProperCase), " Nw.", " NW."), " Sw.", " SW."), " Ne.", " NE."), " Se.", " SE.")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I read it as a dot (period) after the abbreviation, not the end of the sentence.
    In the example in post #1, "1234 ohio st. ne." should be converted to "1234 Ohio St. NE."

    Now you have me wondering....

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    How about checking space before and/or after in the Replace


    ...." se " " se. " etc that would avoid SEaver etc.

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,899
    Even if a space is typed at the end, it shouldn't be there in the data. In my experience, Access trims by default.

    If there is no dot, the only solution I see that has chance of being accurate is orange's VBA function, maybe without the dot code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 1
    Last Post: 06-29-2014, 01:40 PM
  2. Creating a backup email address
    By Paul H in forum General Chat
    Replies: 4
    Last Post: 10-07-2013, 08:57 AM
  3. Replies: 2
    Last Post: 08-22-2013, 12:02 AM
  4. Replies: 4
    Last Post: 11-06-2012, 12:38 PM
  5. Input Mask for an IP Address and Mack Address
    By baksg1995 in forum Access
    Replies: 18
    Last Post: 06-23-2009, 12:33 PM

Tags for this Thread

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