Field with blank spaces

Leesha
BronzeLounger
Posts: 1495
Joined: 05 Feb 2010, 22:25

Field with blank spaces

Post by Leesha »

Hi,
This will be the death of me. I have a [Last_name] and [first_name] which are coming from a table in a database that I didn't set up so I'm not sure why this happens. When the user enters the last name, there a multiple blank spaces. So when I try to join then to produce a string of Last_name, first_name, there is a large gap between the end of the last name, the comma. The result looks something like this:
Smith , Jane

I need to get rid of the spaces after the [last_name]. I've tried reworking the code Hans gave me using using "mid" and "Instr" but it not only keeps blowing up, I don't know how to account for the number of spaces to eliminate.

Thanks!
Leesha

User avatar
HansV
Administrator
Posts: 78676
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Field with blank spaces

Post by HansV »

If you're doing this in a query, try

FullName: Trim([Last_name]) & ", " & Trim([First_name])

In the control source of a text box on a form or report, use

=Trim([Last_name]) & ", " & Trim([First_name])
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1495
Joined: 05 Feb 2010, 22:25

Re: Field with blank spaces

Post by Leesha »

Hans you are the BEST!!! I will be using it in both so I appreciate both scenerios!
Thanks,
Leesha

JohnH
3StarLounger
Posts: 287
Joined: 09 Mar 2010, 23:16
Location: Canberra Australia

Re: Field with blank spaces

Post by JohnH »

Alternatively, get rid of the blank spaces by running an update query that updates each of the two name fields to the trimmed version of each.
Regards

John