Trim Space If A Space Exists At Start

CharlesWhiteman

Registered User.
Local time
Today, 00:09
Joined
Feb 26, 2007
Messages
421
I have written some code which creates a record of a particular action. However, unlike manually entered data these entries have a space st the start of each record.

I cant find exactly what I am looking for on the forum and i could do with some help.

specifically, Access to look at a field and only if a space is at the start then to remove it but not to remove all spaces.

Thanks
 
Code:
if ltrim(Astring) <> Astring then ' Astring starts with one or more spaces.
Astring = mid(Astring,2) ' Get the strinf from the second position
endif
 
if this is related to your other recent post, then it is because you were putting:
Code:
strSql = "values ( ' " & [variable] & " ')"
imagine [variable] was the string "hello", the way you wrote the code create a space on either side, e.g. " hello ". I think you may find that your records have a space at the end as well. see my other post for the solution

HTH,
Chris
 
Yep, this does relate to the other but ta to you both for your input. i am still going to gen up on Guus's post though. Thanks.
 
You might do a search for the trim function or look at help in Access.
or use :

Expr1: Trim([Yourfield]) in your query.
 
You might do a search for the trim function or look at help in Access.
or use :

Expr1: Trim([Yourfield]) in your query.

I agree with Rak. If your purpose is to remove leading space, then use the Trim function. Trim() is often used to remove leading and trailing spaces from user input. You may not need to test for a leading space (it's up to you), but Trim() will remove spaces (leading and trailing) only if they exist.
 
And of course if you wanted to keep one or the other

Code:
Dim szKeepLeft As String
Dim szKeepRight As String

    szKeepLeft = RTrim( spaced_out_string )     '    keeps space on left end
    szKeepRight = LTrim( spaced_out_string )    '    keeps space on the right end
 

Users who are viewing this thread

Back
Top Bottom