Tim:
Do you get an error message, or is there just the sound of crickets chirping and no change to the underlying data?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Trim isn’t working! (Access 97)
Huh, that’s some funky stuff. It wouldn’t Trim, and I didn’t see anything in the properties of the field that would prohibit trimming extraneous spaces. (I used just the Transaction field as a test bed)
I used the InStr function to look for a space character, and it reported back that there were no spaces! I’m going on a hunt for a function that will step through a string and report back what each character is; that is, I see a space, but what does Access see?
Tim,
A space has as ascii value of 32.
Trim is used to remove spaces as they have an ascii value of 32
The strange thing is that the space in your tables, have a value of 160. Why ???? I don’t know.
Here a little function to replace all the space with ascii value of 160 by a space with ascii value of 32.
Put that function in a module and save it.
In your query replace all Trim([YourField]) by Trim(Strip160([YourField]) and run the query
This should work.
Function Strip160(strToStrip As String) As String Dim x As Integer For x = 1 To Len(strToStrip) If Asc(Mid(strToStrip, x, 1)) 160 Then Strip160 = Strip160 & Mid(strToStrip, x, 1) Else Strip160 = Strip160 & " " End If Next x End Function
Francois, you beat me to it! And here I thought I was all clever!
Tim, sure enough, it’s a space, but not a space. Very Zen. Francois’ solution will certainly do the trick for you. I made use of the following function by replacing the Trim([FieldName]) from your original SQL with ChangeStr([FieldName],Chr(160),””,1)
Public Function ChangeStr(strOrig As String, strOldChar As String, _ strNewChar As String, intMatchCase As Integer) As Variant 'This substitutes one character or char string with another as 'designated in the calling function, from KB Q210372 'intMatchCase = 0 means case insensitive comparison; set to 1 for case 'sensitive comparison against strOldChar Dim Temp As String Dim Pos As Integer Temp = "" If IsNull(strOrig) Then ChangeStr = Null Exit Function End If If strOldChar = "" Or strOrig = "" Then ChangeStr = strOrig Exit Function End If Pos = InStr(1, strOrig, strOldChar, intMatchCase) While Pos > 0 Temp = Temp & Mid$(strOrig, 1, Pos - 1) & strNewChar strOrig = Right$(strOrig, Len(strOrig) - Pos - Len(strOldChar) + 1) Pos = InStr(1, strOrig, strOldChar, intMatchCase) Wend ChangeStr = Temp & strOrig End Function
Edited to eliminate horizontal scrolling–Charlotte
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.