473,383 Members | 1,834 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,383 software developers and data experts.

Getting rid of spaces in fields

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 is that the spacing is all screwed up in the
FirstName column. For example, instead of reading John_HS (where _ is
a space), it will read John__H_S__ or John__H__S_.

Any ideas on how to get rid of this superfluous spacing?
Thanks,
Stavrogin.

Nov 13 '05 #1
9 3316
Stavrogin,

I don't think this is the perfect solution
but you can remove all spaces from your text except for single spaces
betwee words using Excel
You have to export your table to an Excel file then use the "Trim"
function on the FirstName column
then import it agin in your Access file

Nov 13 '05 #2
Stavrogin,

I don't think this is the perfect solution
but you can remove all spaces from your text except for single spaces
betwee words using Excel
You have to export your table to an Excel file then use the "Trim"
function on the FirstName column
then import it agin in your Access file

Fatiam

Nov 13 '05 #3
"Stavrogin" <si******@dccnet.com> wrote in
news:11**********************@f14g2000cwb.googlegr oups.com:
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 is that the spacing is all screwed up in
the FirstName column. For example, instead of reading John_HS
(where _ is a space), it will read John__H_S__ or John__H__S_.

Any ideas on how to get rid of this superfluous spacing?
Thanks,
Stavrogin.

If you have Access 2000 or newer, use the replace function in an
update query to replace two spaces with one.

If you are using Access '97, you can find several examples of
how to write your own replace function.
--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #4
Try

Option Compare Database
Option Explicit

Function EliminateSpaces(FirstName As String) As String

Dim i As Integer, j As Integer
Dim Letter As String, OutputStg As String

i = 1
Check:
While i < Len(FirstName) - 1
Letter = Mid$(FirstName, i, 1)
If Letter = " " And Mid$(FirstName, i + 1, 1) = " " Then
i = i + 1
GoTo Check
Else
OutputStg = OutputStg & Mid$(FirstName, i, 1)
End If
i = i + 1
Wend

EliminateSpaces = Trim(OutputStg)

End Function
Phil
"Stavrogin" <si******@dccnet.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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 is that the spacing is all screwed up in the
FirstName column. For example, instead of reading John_HS (where _ is
a space), it will read John__H_S__ or John__H__S_.

Any ideas on how to get rid of this superfluous spacing?
Thanks,
Stavrogin.

Nov 13 '05 #5
Bob Quintal wrote:
If you have Access 2000 or newer, use the replace function in an
update query to replace two spaces with one.
If there's more than 2 spaces, you will need to do several passes on the
query, I'd recommend

update table set firstname = Replace(Firstname," "," ") where FirstName
Like "* *"

Then repeat execution until you get no records updated. (Confirm Action
Queries On and Setwarnings On and put up with the messages for a bit)
If you are using Access '97, you can find several examples of
how to write your own replace function.


Function ReplaceString(pstrtext As String, pstrFind As String,
pstrReplace As String)
Dim i As Long
Dim strText As String
strText = pstrtext

i = 1
i = InStr(i, strText, pstrFind)
Do While i
strText = Left$(strText, i - 1) & pstrReplace & Mid$(strText, i
+ Len(pstrFind))
i = i + Len(pstrReplace)
i = InStr(i, strText, pstrFind)
Loop
ReplaceString = strText
End Function
Nov 13 '05 #6
Trevor Best <no****@localhost.invalid> wrote in
news:43***********************@news.zen.co.uk:

Function ReplaceString(pstrtext As String, pstrFind As String,
pstrReplace As String)
Dim i As Long
Dim strText As String
strText = pstrtext

i = 1
i = InStr(i, strText, pstrFind)
Do While i
strText = Left$(strText, i - 1) & pstrReplace &
Mid$(strText, i
+ Len(pstrFind))
i = i + Len(pstrReplace)
i = InStr(i, strText, pstrFind)
Loop
ReplaceString = strText
End Function

If you change your code slightly to i = InStr(1, strText,
pstrFind)
in both places, the code will take out all occurences of
multiple spaces in one pass. Much faster than rerunning the
query. Beware of replacing x with xy, as that will loop forever.

Function ReplaceString(pstrtext As String, pstrFind As String,
pstrReplace As String)
Dim i As Long
Dim strText As String
strText = pstrtext

i = 1
i = InStr(1, strText, pstrFind)
Do While i
strText = Left$(strText, i - 1) & pstrReplace & Mid
$(strText, i + Len(pstrFind))
i = i + Len(pstrReplace)
i = InStr(1, strText, pstrFind)
Loop
ReplaceString = strText
End Function
--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #7
Bob
Hi,

For A97 users (it also works in later version) this will condense
multiple spaces to a single space. It won't, however, resolve the
problem of John_H_S, where all of the spaces are already single spaces.
That scenario is going to take some coding with validation rules as to
what's appropriate and what's not.

Function OneSpace(pstr As String) As String

'*******************************************
'Purpose: Removes excess spaces from a string
'Input: ? onespace(" now is the time for all good men ")
'Output: "now is the time for all good men"
'*******************************************

Dim strHold As String
strHold = RTrim(pstr)
Do While InStr(strHold, " ") > 0
strHold = Left(strHold, InStr(strHold, " ") - 1) & Mid(strHold,
InStr(strHold, " ") + 1)
Loop
OneSpace = Trim(strHold)

End Function

HTH - Bob

Nov 13 '05 #8
Bob Quintal wrote:
If you change your code slightly to i = InStr(1, strText,
pstrFind)
in both places, the code will take out all occurences of
multiple spaces in one pass. Much faster than rerunning the
query. Beware of replacing x with xy, as that will loop forever.


Or just until the string gets to 2GB :-)

That's why I don't do that, I would assume people would want to use
Replace(something,"'","''") for insertion into an SQL string.

You could of course write a function to specifically remove duplicate
spaces, then apply that in the query, which would then only need one
pass. Personally I'd go that route to be specific about the function's
purpose and call it RemoveDupeSpace() or something rather than hack a
generic function to do something specific and limit it's use.
Nov 13 '05 #9
Trevor Best <no****@localhost.invalid> wrote in
news:43***********************@news.zen.co.uk:
Bob Quintal wrote:
If you change your code slightly to i = InStr(1, strText,
pstrFind)
in both places, the code will take out all occurences of
multiple spaces in one pass. Much faster than rerunning the
query. Beware of replacing x with xy, as that will loop
forever.


Or just until the string gets to 2GB :-)

That's why I don't do that, I would assume people would want
to use Replace(something,"'","''") for insertion into an SQL
string.

You could of course write a function to specifically remove
duplicate spaces, then apply that in the query, which would
then only need one pass. Personally I'd go that route to be
specific about the function's purpose and call it
RemoveDupeSpace() or something rather than hack a generic
function to do something specific and limit it's use.

We think alike.
--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #10

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

Similar topics

6
by: eddie wang | last post by:
How to keep the spaces before the description line in the following code? Right now, it displays like "Net Income", but I like to have spaces before the words like " Net Income". The database...
3
by: Uttam | last post by:
Hello, Using ADO I have created a table and have also created fields. To create fields, I have used the following: ..Columns.Append "Field_Name", adWChar, 6 I load records into this...
4
by: Chuck | last post by:
Hello, I have an Access XP database that has several fields. One of the fields is a text field and has an account number that is preceeded by a text character, like: F102354. Every account...
3
by: SKG | last post by:
i have leading spaces in my database fields. When they appear in the datagrid in browser, they seem to be truncated. I did view source in browser and found that there are indeed spaces but when...
7
by: usenet | last post by:
I would like, if it's possible, to set the value of a field in a table to a number of spaces. One space would be fine, I just want to be able to set the field to a default value that's not NULL...
17
by: tommy | last post by:
Hi all, I' m adding strings to some fields in my table via Access. The strings sometimes have trailing spaces and I really need to have it that way, but Access truncates trailing spaces. How can...
2
by: shadowman | last post by:
So here's the situation: I need to write a PHP script which accepts form submissions using all methods (GET and POST) and all content types (application/x-www-form-url-encoded and...
4
by: koutoo | last post by:
If I have a text file that is delimited by spaces, how do I import it and get to comma delimited? Here is a row of data from the text file: 1 1 10:55:14 2 65 8.5 1.4+1.1 ...
1
by: maryanncanor | last post by:
Hi everyone, My problem is whenever I export a report to a textfile. The output textfile have blank spaces. Here is my query: SELECT ( & '|' & & '|'...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.