Results 1 to 14 of 14
  1. #1
    GregShah is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2012
    Location
    Canton, Ohio
    Posts
    68

    Combining text of different length in Expr but keep even spacing in output

    I have a query with four different fields with data of different lengths. If I just add the fields together, the combined output is tough to read because of the differences in length. Is there a way to allow a set number of spaces for each field so the output appears in orderly columns?

    Thanks,

    Greg

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Why not just show the 4 fields?
    They are automatically in orderly columns.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    GregShah is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2012
    Location
    Canton, Ohio
    Posts
    68
    Quote Originally Posted by Welshgasman View Post
    Why not just show the 4 fields?
    The output is going to be used to name a long series of files. The different field lengths makes the visual of the file list hard to read.

    Like:

    1 ABCD 123
    21 XYZ 24
    124 MNMNMN 541

    I would like to see:

    1 ABCD 123
    21 XYZ 24
    124 MNMNMN 541

    Just looks more orderly.

    Thanks,

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Mock something up in Excel that demonstrates the problem and the desired result (easy) and copy/paste, or post pics of those things. For that you cannot copy/paste pics here. See How to Attach Files at the top of the page.

    If this is about displaying how you want it in a query, users really shouldn't be seeing query results directly, so a form or report may be the right solution.

    EDIT - our post timing is crossing each other so I didn't see that. BTW I see no difference in either of those.
    Maybe all you need is right justify on the first and last columns if those are separate columns.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    If you really need this in one calculated query field, perhaps something like this
    Left("1" & space(4),4) & Left("ABCD" & space(8),8) & "541"

    You'd sub your other query field names for 1, abcd, 541 and choose the number of spaces you want to pad each value with. Here I used 4 and 8
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Well, if that is all you want, concatenate a space or a hyphen between each field
    Could also ProperCase each field?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    GregShah is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2012
    Location
    Canton, Ohio
    Posts
    68
    Quote Originally Posted by Micron View Post
    If you really need this in one calculated query field, perhaps something like this
    Left("1" & space(4),4) & Left("ABCD" & space(8),8) & "541"


    ou'd sub your other query field names for 1, abcd, 541 and choose the number of spaces you want to pad each value with. Here I used 4 and 8
    I will work up a sample in excel but the issue is that each field separately can be a random length. I am hoping to cut and paste the result as the name of a folder. There will be numerous folders and if the columns do not align, makes it a bit messy.

    I don't know why my other samples moved the fields together.

    I am not sure how your suggest fix works. Does it allocate a field of 4 for the first field and then eight for the next? That may do it but never used that convention before.

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    I would use a hyphen between the fields and simple concatenation.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    GregShah is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2012
    Location
    Canton, Ohio
    Posts
    68
    Sample.zip
    Quote Originally Posted by Welshgasman View Post
    I would use a hyphen between the fields and simple concatenation.
    I think I attached a sample file. The results I want are in light blue. Just looks more organized. Plus I can copy and paste to file name.

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    That is much easier to do if all one word?
    I am on my phone, so file no good for me.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Does it allocate a field of 4 for the first field and then eight for the next?
    Sort of. It will pad up to four or eight for first and second respectively. So if a record value is 2, you should get 2 empty spaces to the right of the field value (or eight as the case may be). Or you could just try what someone suggests? There is nothing in your attachment - it is only 1Kb in size.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    You can use the space function in this way

    fld1 & space(10-len(fld1)) & fld2 & space(20-len(fld2)) & etc

    you would need to ensure fld1 cannot be longer than 10 chars and perhaps cater for null values

    however would have thought a listbox would have been a better option

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Your "like" and "would like" in post 3 look identical.

    Posts do not retain repeated spaces in normal text. Use CODE tags.
    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.

  14. #14
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Nothing in the Zipped Folder

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

Similar Threads

  1. Replies: 21
    Last Post: 10-10-2023, 10:49 AM
  2. Replies: 4
    Last Post: 11-28-2017, 02:54 PM
  3. Replies: 5
    Last Post: 07-16-2017, 01:48 AM
  4. Replies: 9
    Last Post: 01-21-2011, 03:57 PM
  5. Expr to Form and Table
    By OpsO in forum Access
    Replies: 3
    Last Post: 07-19-2010, 10:05 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