473,399 Members | 2,278 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,399 software developers and data experts.

Delete a space in a string depending on the fields lenght

I am an infrequent user of Access and have a problem which I hope
someone may be able to help me with. I have a text field in a database
which contains UK postcodes similar to EH4 7TY or DN10 9IU. As shown
in the two examples, a postcode can either have seven characters
including the space in the middle or 8 characters including the space
in the middle. What I would like to do if delete the space from those
postcodes which are 8 characters long while leaving the space in the
shorter postcodes. Hence all the postcodes will then consist of seven
characters. The postcode EH4 7TY should stay as it is with a space
while the postcode DN10 9IU should become DN109IU. Any advice on how
to do this would be appriciated.

Many thanks in advance,

Paul

Nov 13 '05 #1
2 2521
1) Create a backup of the table
2) Create a new query (cancel the select dialog that appears)
3) Switch to SQL view
4) Paste the following SQl in
UPDATE tblPostCodes
SET post_code = IIf(Len([post_code])>7,Left([post_code],InStr([post_code],"
")-1) & Mid([post_code],InStr([post_code]," ")+1),[post_code]);

5) Edit the SQL above replacing the table name and field name with the
correct names from your database.
6) Run the query.
--
Terry Kreft
MVP Microsoft Access
"panorris" <p.********@sms.ed.ac.uk> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I am an infrequent user of Access and have a problem which I hope
someone may be able to help me with. I have a text field in a database
which contains UK postcodes similar to EH4 7TY or DN10 9IU. As shown
in the two examples, a postcode can either have seven characters
including the space in the middle or 8 characters including the space
in the middle. What I would like to do if delete the space from those
postcodes which are 8 characters long while leaving the space in the
shorter postcodes. Hence all the postcodes will then consist of seven
characters. The postcode EH4 7TY should stay as it is with a space
while the postcode DN10 9IU should become DN109IU. Any advice on how
to do this would be appriciated.

Many thanks in advance,

Paul

Nov 13 '05 #2
"panorris" <p.********@sms.ed.ac.uk> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
I am an infrequent user of Access and have a problem which I hope
someone may be able to help me with. I have a text field in a database
which contains UK postcodes similar to EH4 7TY or DN10 9IU. As shown
in the two examples, a postcode can either have seven characters
including the space in the middle or 8 characters including the space
in the middle. What I would like to do if delete the space from those
postcodes which are 8 characters long while leaving the space in the
shorter postcodes. Hence all the postcodes will then consist of seven
characters. The postcode EH4 7TY should stay as it is with a space
while the postcode DN10 9IU should become DN109IU. Any advice on how
to do this would be appriciated.

Many thanks in advance,

Paul


What about postcodes like "N1 9JN"? Will you try to add two spaces to make
it seven characters long? I don't really see the point in doing this, but
if you know how to do update queries, you could remove all spaces from all
postcodes using Replace(MyField, " ", "") and then put the space back in
using the left and right functions, e.g.

NewPostcode:Left([MyField],Len([MyField])-3) & " " & Right([MyField],3)

Nov 13 '05 #3

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

Similar topics

5
by: Mike | last post by:
I am not a sql person and could use some help with a delete...here is what I want: I have the following tables/fields (only including necessary fields) answers result_id results result_id
8
by: cdolphin88 | last post by:
Hi, I'm reading from a .dat file and I want to know the length of the string . I' using the stringRef.length () but the compiler said there was an error `stringRef' undeclared (first use...
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
12
by: JA | last post by:
Is there a way to remove all the white space in the fields? I have been using Find-and-replace - looking for 2 or 3 or 4 or 10 spaces and replacing them with none. I don't want to replace single...
3
by: igendreau | last post by:
I'm trying to clean up a database of mine, and I need to convert some old DAO code over to ADO. When I was using DAO, I had no problem running this script and deleting the record using rs.Delete. ...
1
by: psawant | last post by:
Hi All, i have two accepted formats. expectedFormats = New String() {"%M/%d/yyyy", "%M/%d/yyyy hh:mm:ss tt"} dt = DateTime.ParseExact(txtInpDateString.Text, expectedFormats,
1
by: parez | last post by:
Hi All, i have two accepted formats. expectedFormats = New String() {"%M/%d/yyyy", "%M/%d/yyyy hh:mm:ss tt"} dt = DateTime.ParseExact(txtInpDateString.Text, expectedFormats,...
1
by: Barok | last post by:
hello peeps, i just startet to coding in c, and dont have a big background. now i have a problem witch i dont understand. i hope you guys can help me out here. the problem is malloc. i try...
2
by: farouqdin | last post by:
Hi all i have code which loops through table and deletes the duplicate records. This code does it for one table. How do i change it so it goes through several tables? On Error Resume Next Dim...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.