Results 1 to 9 of 9
  1. #1
    StGermain is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    20

    ENVELOPE PRINTING: How to combine city/state/zip code fields into a single field (no extra spaces)?

    Click image for larger version. 

Name:	COMPLETE ADDRESS.jpg 
Views:	16 
Size:	37.3 KB 
ID:	44588Click image for larger version. 

Name:	ERROR.jpg 
Views:	15 
Size:	19.1 KB 
ID:	44589

    Thanks for help with this totally-new Access user question.

    I am trying to create a report to print mailing envelopes.

    I tried to research how to do this online, but despite several hours of waste time it still does not work.

    Please see the two screenshots.

    Here is what I put in the box for the last line:

    =[City] & (", "+[State/Province]) & (" "+[Zip/Postal Code])


    You can see the screenshot with the error

    Anybody's help is appreciated.
    Thanks

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,906
    I never use + for concatenation, despite it working in some ways.
    Just use the & instead. Hopefuly you ALWAYS have values for these, else you will need to test for what you have?
    Code:
    =[City] & ", " & [State/Province] & "  " & [Zip/Postal Code]
    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
    StGermain is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    20
    Click image for larger version. 

Name:	errors.jpg 
Views:	14 
Size:	59.9 KB 
ID:	44591

    Thanks for your reply.

    I pasted that in, but still get errors as shown in screen shot

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,778
    In a report you can refer to fields in the recordsource even if there are no controls bound to those fields. Not sure you can do that on a form - never tried. Regardless, there is no evidence in your post that you have those fields in the recordsource or as controls on the form. If not, you can't use them in your concatenation.

    EDIT - Just tested and yes, you can refer to a recordsource field for a form if there is no control on the form that is bound to it. Anyway, that's the question before you. Are your 3 fields part of the recordsource at least? Plus, you have a 2 part problem - circular reference in that expression. Likely one of the elements in the reference is also referencing the same thing. Click on the error and see what info it gives you for the circular reference.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    StGermain is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    20
    Here are the fields. I think they do match the report in question?
    Click image for larger version. 

Name:	correct field names.jpg 
Views:	14 
Size:	38.3 KB 
ID:	44592

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,906
    I am also puzzled by that circular reference?
    What have you called the textbox that holds the concatenation data?
    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
    StGermain is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    20
    Yes, you nailed it! I had named the textbox "city" (i.e. same as already-existing "city" field).

    I changed it to "Last Address Line" -- and now it displays correctly.

    Thanks so much.

    ANOTHER SMALL PROBLEM maybe you can solve for me too?

    The print view shows a SECOND "blank" page -- with a gray bar at the top.

    Here is what it looks like . . .

    And also here is what the design view looks like . . .

    Click image for larger version. 

Name:	second blank page.jpg 
Views:	27 
Size:	32.3 KB 
ID:	44593

    Click image for larger version. 

Name:	design view.jpg 
Views:	23 
Size:	114.7 KB 
ID:	44594

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by Welshgasman View Post
    I never use + for concatenation, despite it working in some ways.
    Just use the & instead. Hopefuly you ALWAYS have values for these, else you will need to test for what you have?
    Code:
    =[City] & ", " & [State/Province] & "  " & [Zip/Postal Code]
    Using the + as was done is a neat trick to account for Null values. + will propagate Null, & will not. Thus if [State/Province] is Null below, you will not see the comma. You'll only get the comma if there's a value in the field:

    =[City] & (", "+[State/Province]) & (" "+[Zip/Postal Code])

    Note only 1 comma:

    ?"blah" & ("," + null) & ("," + "test")
    blah,test
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,906
    Quote Originally Posted by StGermain View Post
    Yes, you nailed it! I had named the textbox "city" (i.e. same as already-existing "city" field).

    I changed it to "Last Address Line" -- and now it displays correctly.

    Thanks so much.

    ANOTHER SMALL PROBLEM maybe you can solve for me too?

    The print view shows a SECOND "blank" page -- with a gray bar at the top.

    Here is what it looks like . . .

    And also here is what the design view looks like . . .

    Click image for larger version. 

Name:	second blank page.jpg 
Views:	27 
Size:	32.3 KB 
ID:	44593

    Click image for larger version. 

Name:	design view.jpg 
Views:	23 
Size:	114.7 KB 
ID:	44594
    Have you adjusted the report for the envelope depth?
    Have you selected the correct size option in design mode?
    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

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

Similar Threads

  1. API to find City,State given a zip code
    By GraeagleBill in forum Programming
    Replies: 6
    Last Post: 03-18-2019, 12:11 PM
  2. Replies: 9
    Last Post: 05-26-2016, 05:13 PM
  3. How to remove extra spaces from a field?
    By accessmatt in forum Queries
    Replies: 1
    Last Post: 09-22-2014, 06:57 AM
  4. Texas City,State,Zip and Area Code
    By burrina in forum Sample Databases
    Replies: 0
    Last Post: 11-12-2012, 10:35 PM
  5. City, State Zip lookup
    By garywmcp in forum Access
    Replies: 1
    Last Post: 04-24-2011, 06:15 PM

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