Results 1 to 13 of 13
  1. #1
    CP611 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55

    How to Get Rid of an extra space

    I currently have a make table query which contains the formula ADDRESSLINE1: StrConv([Address],3) & (Chr(13)+Chr(10)+StrConv([Address2],3)) so that it combined Address and Address2 into one cell, making sure to convert it into capitals and put Address2 onto a new line. This works fine however when there is nothing in Address2 it still puts in an enter. Therefore, when it is imported into a CRM system and mail merges are created it will look like this:



    Mr Smith
    20 Smith Lane

    London
    SW19 8DF

    Is there a way to remove the extra enter line if the Address2 is blank?

    Thanks (very new to this so not really sure what I'm doing!)

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Check to see if there is a value in Address2 before adding it, i.e.
    Code:
    ADDRESSLINE1: StrConv([Address],3) & IIF([Address2]<>"",(Chr(13)+Chr(10)+StrConv([Address2],3)),"")

  3. #3
    CP611 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    That's great thank you!

    Another one... is there a way to format postcodes so they come out correctly? Some of them would have been entered correctly but others may not have a space in. At the moment I've got:
    POSTCODE: StrConv([Postal Code],1)

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    How are they not coming out correctly?
    Can you post a few examples of ones that work, and ones that do not?

  5. #5
    CP611 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    Hi,
    Some will go in as SW19 2JI for example and come out correctly. Others will go in as LS192BH and come out the same, i.e. without the space in, whereas I would want them to come out as LS19 2BH, but obviously not every postcode is the same, I believe they all have 3 letters in the second half but some have just G1 in the first half for example.

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    So, do they allow follow the same rule, where it should be 4 characters, followed by 1 space, followed by three characters?
    And the issue is that some already have the space in there, and others don't?

    If so, this should do it:
    Code:
    POSTCODE: Left([Postal Code],4) & " " & Right([Postal Code],3)

  7. #7
    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
    Try this where x represents your postal code

    IIf(InStr(x, " ") > 0, x, Left(x, 4) & " " & Mid(x, 5))

  8. #8
    CP611 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    The one with x in doesn't seem to work, says invalid syntax error
    The issue is that some already have a space in and others don't, however the postcodes are not always the same, some are XX XXX some are XXX XXX some are XXXX XXX.
    E.g. Input:
    SW16 8PQ, SW18TH, SW3 4EW, SW323KL would be: SW16 8PQ, SW1 8TH, SW3 4EW, SW32 3KL. I.e. always has 3 characters in the second section.

    Thanks

  9. #9
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Here is one way:
    Code:
    POSTCODE: Left([Postal Code],Len(Replace([Postal Code]," ",""))-3) & " " & Right([Postal Code],3)

  10. #10
    CP611 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    55
    that seems to work! Thanks

  11. #11
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You are welcome.

  12. #12
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,975
    You might be interested in this info about the structure of UK postcodes which is supplied with one of my commercial apps.
    Attached Files Attached Files
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  13. #13
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Try one more:
    Code:
    PostalCode: Replace([Postal Code]," ","")
    and set the format property to:
    >&&&& &&&

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

Similar Threads

  1. Replies: 6
    Last Post: 05-25-2018, 09:53 AM
  2. Replies: 6
    Last Post: 07-06-2015, 11:57 AM
  3. remove extra white space from duplicate field
    By ensorde in forum Reports
    Replies: 2
    Last Post: 10-01-2014, 08:31 AM
  4. Extra ( in strWhere
    By TinaCa in forum Programming
    Replies: 2
    Last Post: 10-10-2011, 02:18 PM
  5. Extra space added
    By allenf in forum Forms
    Replies: 2
    Last Post: 07-25-2010, 06:57 AM

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