Consulting

Results 1 to 3 of 3

Thread: Revise query

  1. #1
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location

    Revise query

    I have a query:

    USAO_LOC: ([USAO_PHY_LOC] & Chr(11))+([USAO_ADDR_1]) & (Chr(11)+[USAO_ADDR_2]) & (Chr(11)+[USAO_ADDR_3])

    Which is intended to create mailing address block e.g.,

    Thomas A. Bubblebutt Federal Building
    123 Main Street
    Anytown, FL 12345

    Sometimes it is just two lines:
    P.O. Box 123
    Anytown, FL 12345


    As it is, I'm getting a undesired leading line break Chr(11) when there is no data defined for USAO_PHY_LOC

    How can I revise the query to eliminate that break. Thanks.

    Cross posted at: http://answers.microsoft.com/en-us/o...=1393379438895
    Last edited by gmaxey; 02-25-2014 at 06:51 PM.
    Greg

    Visit my website: http://gregmaxey.com

  2. #2
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    Create a public function. If you use a paramarray you can easily add more fields in furture if you like.

    Public Function Address(ParamArray p() As Variant) As String
        For Each itm In p
            If Len(Trim(CStr(itm))) Then
                If Len(Address) Then Address = Address & vbCrLf
                Address = Address & itm
            End If
        Next
    End Function
    And call it from you query: e.g.

    addr: Address([field1],[field2],[field3], ... )

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    John,

    Thanks. I had received a similar suggestion to use a GetShrinkLines function. That worked great for the query in access, but when I tried to get to my data using and RecordSet SQL statement it crashes. I've found a solution.
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •