473,378 Members | 1,321 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Extra spaces in Access Records.

I've been trying to get rid of extra spaces in a table that I created
with addresses in it.

For instance in a field called TEST, I got the following address:

" 1 main st Apt A "
First I tried to use the "trim", "ltrim" and "rtrim" functions, these
functions did work, but only for those spaces at the beginning and at
the end of the record, so the result was:

"1 main st Apt A"

But I still haven't figure out how to get rid of the spaces in the
middle of the record, the ones in between the words. In excel the trim
function does the trick, but in access it does not.

Please let me know of a function or instruction that deletes these
spaces in between the words.

Any help is greatly appreciated.

Thanks.
Nov 12 '05 #1
5 4040
Marco Gallo wrote:
I've been trying to get rid of extra spaces in a table that I created
with addresses in it.

For instance in a field called TEST, I got the following address:

" 1 main st Apt A "
First I tried to use the "trim", "ltrim" and "rtrim" functions, these
functions did work, but only for those spaces at the beginning and at
the end of the record, so the result was:

"1 main st Apt A"

But I still haven't figure out how to get rid of the spaces in the
middle of the record, the ones in between the words. In excel the trim
function does the trick, but in access it does not.

Please let me know of a function or instruction that deletes these
spaces in between the words.

Any help is greatly appreciated.

Thanks.


Call a function. You can drop the below function in a code module.
Then create an update query. Drag the field down to be updated. Lets
call it Address. In the Update To row of the query enter
RemExtraSpaces([Address])

You can test this function out by entering
? RemExtraSpaces("1 main st Apt A")
in the immediate window.

BTW, make a copy of the table first before you run...just to be sure.

One other note. It removes duplicate spaces only. If the first/last
chars are spaces, they remain.

Public Function RemExtraSpaces(strWord As Variant) As String
If Not IsNull(strWord) Then
Dim intFor As Integer

For intFor = 1 To Len(strWord)
RemExtraSpaces = RemExtraSpaces & _
Mid(strWord, intFor, 1)

If Mid(strWord, intFor, 1) = Space(1) Then
While Mid(strWord, intFor, 1) = Space(1) And _
intFor < Len(strWord)

intFor = intFor + 1
Wend
intFor = intFor - 1
End If
Next intFor
End If
End Function

Nov 12 '05 #2
I think you should write a little procedure along these lines:
Function GRS(StrS As String) As String
'gets rid of spaces in strings
On Error GoTo er
'--------------------
Dim StrS2 As String
Dim StrS3 As String
Dim i As Long
'--------------------
StrS = Trim(StrS)
For i = 1 To Len(StrS)
StrS2 = Mid(StrS, i, 1)
If StrS2 = " " And StrS3 = " " Then
'do nothing
Else
GRS = GRS & StrS2
End If
StrS3 = StrS2
Next i
xt:
Exit Function
er:
GRS = StrS
Resume xt
End Function

"Marco Gallo" <mw*****@tecopartners.com> wrote in message
news:93*************************@posting.google.co m...
I've been trying to get rid of extra spaces in a table that I created
with addresses in it.

For instance in a field called TEST, I got the following address:

" 1 main st Apt A "
First I tried to use the "trim", "ltrim" and "rtrim" functions, these
functions did work, but only for those spaces at the beginning and at
the end of the record, so the result was:

"1 main st Apt A"

But I still haven't figure out how to get rid of the spaces in the
middle of the record, the ones in between the words. In excel the trim
function does the trick, but in access it does not.

Please let me know of a function or instruction that deletes these
spaces in between the words.

Any help is greatly appreciated.

Thanks.

---
Please immediately let us know (by phone or return email) if (a) this email
contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.688 / Virus Database: 449 - Release Date: 18/05/2004
Nov 12 '05 #3
Maybe something like this:
Expand|Select|Wrap|Line Numbers
  1. Function onespace(pStr As String) As String
  2. '*******************************************
  3. 'Purpose:   Removes excess spaces from a string
  4. 'Inputs:    ? onespace(" the    quick    brown fox   ")
  5. 'Output:    "the quick brown fox"
  6. '*******************************************
  7.  
  8. Dim strHold As String
  9.  
  10. strHold = RTrim(pStr)
  11.  
  12. Do While InStr(strHold, "  ") > 0 '"  " = 2 spaces
  13. strHold = Left(strHold, InStr(strHold, "  ") - 1) & Mid(strHold,
  14. InStr(strHold, "  ") + 1)
  15. Loop
  16.  
  17. onespace = Trim(strHold)
  18.  
  19. End Function
  20.  
Best wishes, Imboden
Nov 13 '05 #4
rkc

"Imboden" <im*****@zalau.ro> wrote in message
news:bb**************************@posting.google.c om...
Maybe something like this:
Expand|Select|Wrap|Line Numbers
  1.  Function onespace(pStr As String) As String
  2.  '*******************************************
  3.  'Purpose:   Removes excess spaces from a string
  4.  'Inputs:    ? onespace(" the    quick    brown fox   ")
  5.  'Output:    "the quick brown fox"
  6.  '*******************************************
  7.  Dim strHold As String
  8.  strHold = RTrim(pStr)
  9.      Do While InStr(strHold, "  ") > 0 '"  " = 2 spaces
  10.        strHold = Left(strHold, InStr(strHold, "  ") - 1) & Mid(strHold,
  11.  InStr(strHold, "  ") + 1)
  12.      Loop
  13.      onespace = Trim(strHold)
  14.  End Function
  15.  

s = trim (s)
do while instr(s," ") > 0
s = replace(s, " ", " ")
loop

Nov 13 '05 #5
> s = trim (s)
do while instr(s," ") > 0
s = replace(s, " ", " ")
loop


Right!

Should have included:

Written in A97 (no Replace() function exists)

Best Wishes, Imboden
Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ragnorack67 | last post by:
Hi, I need some advice on what to do. I have this MySQL insert file, with about 30,000 records. One of the datafields has names in it. When this list was put together, apparently there was extra...
6
by: Ruben | last post by:
Hello. I am trying to read a small text file using the readline statement. I can only read the first 2 records from the file. It stops at the blank lines or at lines with only spaces. I have a...
2
by: Maurice KRAIT | last post by:
Hello all, I use ACCESS 97. I want to delete all records of a table "TABLE RESULT" , the name of which includes spaces. It seems to me that the correct syntax is as follows : DoCmd.RunSQL ...
1
by: Sean Howard | last post by:
Dear All, As is my want I need to do something in Access that seems simple but cannot fathom out. I have main form with two subforms, both datasheets with an almost identical table structure....
9
by: Stavrogin | last post by:
Hi, I have a database of about 10,000 individuals. One column is devoted to a person's surname (LastName) and another column to their first name and inititals (FirstName). One problem I have...
5
by: dw | last post by:
hello - first, let me state that i am an Asp.Net rookie. here is the situation: i have a page that looks good in the vs.net designer, but when the page renders there are extra amounts...
7
by: Bosconian | last post by:
I know that str.replace(/^\s+|\s+$/g,''); will trim a string of space, but what about removing extra spaces from the middle? Where "hello world"
3
by: dchristjohn | last post by:
I am currently developing a small windows application using Visual Basic via Visual Studio 2005. My database resides on a SQL 2000 server. I have a table with three fields: id (int, Not Null)...
2
code green
by: code green | last post by:
I am trying to write a simple function that will take a string containing an address line or business name and return it nicely formatted. By this I mean extra spaces removed and words capitalised....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.