View Full Version : Concatenating using +


lmcc007
07-21-2009, 05:03 PM
Okay, I took you'll suggestions and concatenate using a query, but I am still getting empty spaces and blanks. I have been working on it all day and can't find what I am doing wrong. I have the attached the db with the query (qryFullAddress) in hopes someone can see what I missed. Any help is surely appreciated.

marianne
07-21-2009, 05:08 PM
whats the problem?

lmcc007
07-21-2009, 05:10 PM
whats the problem?

When a field is empty, I am getting blank line or empty space.

lmcc007
07-21-2009, 05:16 PM
whats the problem?

I added the fields to "qryFullAddress with fields" so you can better see what I am talking about.

marianne
07-21-2009, 05:25 PM
what do you want to achieve here?

lmcc007
07-21-2009, 05:32 PM
what do you want to achieve here?

Eliminate the blank lines and empty spaces.

marianne
07-21-2009, 05:34 PM
how about this one... i have made modification on the said query.

lmcc007
07-21-2009, 05:38 PM
how about this one... i have made modification on the said query.

No, everything is join together. All I am trying to do is get my address to look properly on a form or if I decide to print them, and so. For example:

c/o ABC
ABC Tenant Inc.
123 Nowhere Lane
NY, New York 11234

Attn: CBS
CBS Production
222 Eastside N Avenue
Chicago, IL 12346

PO Box 1000
Houston, TX 77002

marianne
07-21-2009, 05:47 PM
i see. let me test again.

stopher
07-21-2009, 10:48 PM
Eliminate the blank lines and empty spaces.

Try this:

FullAddress: ([Attention]+(Chr(13) & Chr(10))) & ((IIf(IsNull([StreetNumber]),Null,CStr([streetnumber]))+" ") & ([PreDirection_Lkp]+" ") & ([StreetName]+" ") & [PostDirection_Lkp])+(Chr(13) & Chr(10)) & ([DesignationType]+" ") & ([Designation]+(Chr(13) & Chr(10))) & ([BoxType_Lkp]+" ") & ([BoxNumber]+(Chr(13) & Chr(10))) & ([City]+", ") & ([State]+" ") & ([ZipCode]+"-")+[ZipExt]

I found the numeric was causing a problem so I use the IIF to generate a variant. Presumably when seeing a number, the + operator tries to add not concatenate. This approach sorts out your extra spaces.

I also put brackets around all the Chr(13) & chr(10). If you consider [BoxNumber]+Chr(13) & Chr(10), then when box number is null, then the result will be only chr(10) since the operation [BoxNumber]+Chr(13) will be performed first - hence your extra line breaks.

As Bob Larson mentioned in another of your threads, you have kind of gone overboard with the normalisation. I too would put company name in the mane table and I'd take pretty much the same approach for all the other tables. It doesn't matter that you have blanks for no company name. This can always be managed in a query.

hth
Chris

neileg
07-22-2009, 12:53 AM
Concatenation using + will preserve nulls, hence the blanks. Concatenation using & does not.

lmcc007
07-22-2009, 09:23 AM
Try this:

FullAddress: ([Attention]+(Chr(13) & Chr(10))) & ((IIf(IsNull([StreetNumber]),Null,CStr([streetnumber]))+" ") & ([PreDirection_Lkp]+" ") & ([StreetName]+" ") & [PostDirection_Lkp])+(Chr(13) & Chr(10)) & ([DesignationType]+" ") & ([Designation]+(Chr(13) & Chr(10))) & ([BoxType_Lkp]+" ") & ([BoxNumber]+(Chr(13) & Chr(10))) & ([City]+", ") & ([State]+" ") & ([ZipCode]+"-")+[ZipExt]

I found the numeric was causing a problem so I use the IIF to generate a variant. Presumably when seeing a number, the + operator tries to add not concatenate. This approach sorts out your extra spaces.

I also put brackets around all the Chr(13) & chr(10). If you consider [BoxNumber]+Chr(13) & Chr(10), then when box number is null, then the result will be only chr(10) since the operation [BoxNumber]+Chr(13) will be performed first - hence your extra line breaks.

As Bob Larson mentioned in another of your threads, you have kind of gone overboard with the normalisation. I too would put company name in the mane table and I'd take pretty much the same approach for all the other tables. It doesn't matter that you have blanks for no company name. This can always be managed in a query.

hth
Chris

I don't understand the CompanyName part b/c when I asked this question a couple of months ago I was told to put CompanyName in another table. There are about 400 blind ads w/o a CompanyName. I use (N/A) when there is no CompanyName.

boblarson
07-22-2009, 09:28 AM
Concatenation using + will preserve nulls, hence the blanks. Concatenation using & does not.

Actually Chris, I think you got that backwards. If you use the + blanks will not appear whereas if you use the ampersand (&) blanks will remain.

lmcc007
07-22-2009, 09:36 AM
Try this:

FullAddress: ([Attention]+(Chr(13) & Chr(10))) & ((IIf(IsNull([StreetNumber]),Null,CStr([streetnumber]))+" ") & ([PreDirection_Lkp]+" ") & ([StreetName]+" ") & [PostDirection_Lkp])+(Chr(13) & Chr(10)) & ([DesignationType]+" ") & ([Designation]+(Chr(13) & Chr(10))) & ([BoxType_Lkp]+" ") & ([BoxNumber]+(Chr(13) & Chr(10))) & ([City]+", ") & ([State]+" ") & ([ZipCode]+"-")+[ZipExt]

I found the numeric was causing a problem so I use the IIF to generate a variant. Presumably when seeing a number, the + operator tries to add not concatenate. This approach sorts out your extra spaces.

I also put brackets around all the Chr(13) & chr(10). If you consider [BoxNumber]+Chr(13) & Chr(10), then when box number is null, then the result will be only chr(10) since the operation [BoxNumber]+Chr(13) will be performed first - hence your extra line breaks.

As Bob Larson mentioned in another of your threads, you have kind of gone overboard with the normalisation. I too would put company name in the mane table and I'd take pretty much the same approach for all the other tables. It doesn't matter that you have blanks for no company name. This can always be managed in a query.

hth
Chris

Thanks a bunch for this code! I am embarrassed to say how long I have been working on it. Thanks again!

stopher
07-22-2009, 10:01 AM
Actually Chris, I think you got that backwards. If you use the + blanks will not appear whereas if you use the ampersand (&) blanks will remain.Bob, I think you mean Neil ;)

Regards
Chris

boblarson
07-22-2009, 10:20 AM
Bob, I think you mean Neil ;)

Regards
Chris

Yep, my bad... sorry Chris :D :o

lmcc007
07-22-2009, 10:57 AM
Stopher,

Any suggestions on how to handle CompanyNames? I don't want duplicate CompanyNames, but I have about 400 blind ads.

neileg
07-23-2009, 02:11 AM
Bob, I think you mean Neil ;)

Regards
ChrisI think he meant Neil, and yes I got it backwards! ;)