Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trim Data Question

Status
Not open for further replies.

sibleytr

Technical User
Jan 27, 2005
21
US
I am needing to build a field using the data from four other fields using an Access Query.

Code:
strFullStName: [PREDIRECT]&" "&[STREETNAME]&" "&[STREETTYPE]&" "&[POSTDIRECT]

From the above code you can see the problem if any field, specificly the outer two fields are empty I wind up with a space in from of and/or behind my created data if some data fields are null.

Any ideas on how I can set an IIf condition or simply trim out the spaces on either end without making a second pass over the data?
 
To just trim the outlying spaces:

Code:
strFullStName: Trim([PREDIRECT]& " " &[STREETNAME]& " " & [STREETTYPE]& " " & [POSTDIRECT])

This, of course, does nothing with the internal spaces...

traingamer
 
strFullStName: [PREDIRECT] & IIf(IsNull([STREETNAME]),""," " & [STREETNAME]) & IIf(IsNull([STREETTYPE]),""," " & [STREETTYPE]) & IIf(IsNull([POSTDIRECT]),""," " & [POSTDIRECT])

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I don't know what my computer has been smoking but I re-ran my previous.

Code:
FullStreetName: Trim([PREDIRECT] & " " & [STREETNAME] & " " & [STREETTYPE] & " " & [POSTDIRECT])

and the query worked this time.

Time to crush the bugs with a format do over.

Thanks again.
 
and the query worked this time
Even with a null STREETTYPE and a valid POSTDIRECT ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
the Trim command by itself only trimed the outer ends of the data, I had to use your IIF to make it really massage the data they proper way.

Thanks for the code. It is greatly apprecaited.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top