Problem trimming a string. (1 Viewer)

odin1701

Registered User.
Local time
Today, 13:04
Joined
Dec 6, 2006
Messages
526
I have a string, which is an account number. ex: 111222233333

When I get the account number from the field in the form I get this as a result:

" 111222233333"

It has a space at the beginning. However, when I try to do any of the following, it still has a leading space:

Trim(acctNum.value)
LTrim(acctNum.value)

Or if I define a string

Dim strAcct as String
stracct = acctNum.value
strAcct = Trim(strAcct)

Still the leading space. What am I doing wrong?

Is there a function that I can use to just delete the first character, whatever that character is. Maybe it isn't a space somehow??

I'm also confused as to why there is a leading space when it doesn't show in the field on the form or the table the data is in. I did not make this database, I'm just fixing it (ugh).
 

KeithG

AWF VIP
Local time
Today, 12:04
Joined
Mar 23, 2006
Messages
2,592
Interesting I don't know what the problem would be. Try using the replace funtion to replace the blank space with nothing

Replace("String"," ","")
 

odin1701

Registered User.
Local time
Today, 13:04
Joined
Dec 6, 2006
Messages
526
Interesting I don't know what the problem would be. Try using the replace funtion to replace the blank space with nothing

Replace("String"," ","")

Well tried that and there is still a space or blank or something in front. I don't understand why though.
 

odin1701

Registered User.
Local time
Today, 13:04
Joined
Dec 6, 2006
Messages
526
Also, I pulled a number from a different field and it also has a leading space. This makes no sense.
 

RuralGuy

AWF VIP
Local time
Today, 13:04
Joined
Jul 2, 2005
Messages
13,825
Put in a diagnostic message box:
MsgBox "1st character code is [" & Asc([YourString]) & "]"

...the Asc() function looks at the 1st character in the string and a space would be 32 decimal.
 

JohnLee

Registered User.
Local time
Today, 12:04
Joined
Mar 8, 2007
Messages
692
Put in a diagnostic message box:
MsgBox "1st character code is [" & Asc([YourString]) & "]"

...the Asc() function looks at the 1st character in the string and a space would be 32 decimal.

Hi,

Could I make a suggestion, I have found sometimes for some reason in the underlaying table in the field concerned that sometimes people set the default value to " ", which forces a space no matter what, You may have already checked this out, but sometime the simple things get overlooked.

John
 

odin1701

Registered User.
Local time
Today, 13:04
Joined
Dec 6, 2006
Messages
526
Put in a diagnostic message box:
MsgBox "1st character code is [" & Asc([YourString]) & "]"

...the Asc() function looks at the 1st character in the string and a space would be 32 decimal.

Cool....I did that. It's 160.

So I did:

acctNum = Replace(acctNum, Chr(160), "")

That fixed it. I still have no clue how that character gets in there. I already did check the defaul value for that field and there's nothing in there that would cause it.
 

BrettStah

Registered User.
Local time
Today, 14:04
Joined
Apr 15, 2007
Messages
49
CHR(160) is a non-breaking space character, commonly used on HTML pages.
 

BrettStah

Registered User.
Local time
Today, 14:04
Joined
Apr 15, 2007
Messages
49
That is very very odd...this has no HTML code or anything to do with website stuff at all.

That is just one of the common places it is used. It is by no means limited to HTML pages, as you've discovered. :)
 

Users who are viewing this thread

Top Bottom