473,509 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change a lot of words in a table

Hi!

A have a problem. I have a table containing
ID,Brend,Model,Colour,Price.
The Colour field has colours like: YELLOW/BLACK/RED, YELLOW/RED, BLUE,
BLUE/NAVY/RED/CHARCOAL.
Now i would like to shorten them like this
YELLOW->YEL,BLACK->BLK,WHITE->WHT...
so that the colour field would look like this YEL/BLK/RED and so on.
Please help!

Marko

Nov 13 '05 #1
15 1613
Bob
Marko -

A paramArray works pretty well in a situation where you have a number
of items to check for. It might be a tad slow for a large number of
records, but since this appears to be a one-time shot, it well may be
worth the wait.

******************** the code ********************
Public Function ReplHue(pStr As String, ParamArray varMyVals() As
Variant) As String
'*******************************************
'Re:
http://groups.google.com/group/comp....access/browse_
frm/thread/077757357b36d7da/44153ba1796871c6?hl=en#44153ba1796871c6
'Purpose: Replace specified portion of
' string with another designation.
'Coded by: raskew
'Inputs: from debug (immediate) window
' ? replHue("Green/White/Red/Black", "Yellow", "Yel",
"Black", "Blk", "White", "Wht")
'Output: Green/Wht/Red/Blk
'*******************************************

Dim i As Integer
Dim n As Integer
Dim strHold As String

strHold = pStr

For i = 0 To UBound(varMyVals) Step 2

n = InStr(strHold, varMyVals(i))

If n > 0 Then

strHold = Left(strHold, n - 1) & varMyVals(i + 1) &
Mid(strHold, n + Len(varMyVals(i)))

End If

Next i

ReplHue = strHold

End Function

******************** end code ********************

You can test it as shown in the comments. Once satisfied with its
operation,
with the options modified to meet your needs, create a test query with
a calculated field showing the results after applying ReplHue, e.g.
**********query starts**********
SELECT
tblColor2.ID
, tblColor2.Color
, replHue([color],"Yellow","Yel","Black","Blk","White","Wht") AS
Fixed
FROM
tblColor2;
**********query ends************
(replace table and field names as necessary)

Finally, after backing-up your table!!!, create an update query using
the logic shown above.

HTH - Bob

Nov 13 '05 #2
one way is to loop through the field in that table and update a piece
at a time. Use SPLIT to break out the values into single values and
then read them and sub out. then reassemble the thing when you're done.

Nov 13 '05 #3
one way is to loop through the field in that table and update a piece
at a time. Use SPLIT to break out the values into single values and
then read them and sub out. then reassemble the thing when you're
done.

of course, if you stored this in a more normalized way, none of this
would be necessary at all. You could run a few update queries and be
done with it.

Nov 13 '05 #4
Bob
Suspect that one update-query could sort it all out. What say you?

Bob

Nov 13 '05 #5
marko wrote:
Hi!

A have a problem. I have a table containing
ID,Brend,Model,Colour,Price.
The Colour field has colours like: YELLOW/BLACK/RED, YELLOW/RED, BLUE,
BLUE/NAVY/RED/CHARCOAL.
Now i would like to shorten them like this
YELLOW->YEL,BLACK->BLK,WHITE->WHT...
so that the colour field would look like this YEL/BLK/RED and so on.
Please help!

Marko


First note: It certainly looks like your table design is bad.

If you have a record that needs more than one color recorded for it,
almost always you then need a color table related to the original table. It
eliminates a lot of problems. That is the way a database works.

Say after me, Access is a database not a spreadsheet. :-)

This technique is called normalization and there is information on it in
the Access help files or almost any book on databases.

--
Joseph Meehan

Dia duit
Nov 13 '05 #6
Bob
Marko -

We've got the normalization 'mini-lectures' from Joseph and pietlin, et
al.
Let's wait and see if they provide a viable solution as to how to get
out of the problem.

It sounds good when you say it fast, but did you notice that they are
not providing any solutions towards solving the problem?

Bob

Nov 13 '05 #7

"marko" <ma*****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi!

A have a problem. I have a table containing
ID,Brend,Model,Colour,Price.
The Colour field has colours like: YELLOW/BLACK/RED, YELLOW/RED, BLUE,
BLUE/NAVY/RED/CHARCOAL.
Now i would like to shorten them like this
YELLOW->YEL,BLACK->BLK,WHITE->WHT...
so that the colour field would look like this YEL/BLK/RED and so on.
Please help!

Marko


Marko,

If this is something you will need to do regularly, then you probably should
create a fancy function like others suggest. If, however, this is a one shot
deal, and you have A2K or later, you could do it very easily with some ugly
but effective brute force code.

DoCmd.RunSQL "Update tblName Set Colour=Replace(Colour,'YELLOW','YEL')"

DoCmd.RunSQL "Update tblName Set Colour=Replace(Colour,'BLACK','BLK')"

DoCmd.RunSQL "Update tblName Set Colour=Replace(Colour,'WHITE','WHT')"

etc...

And, as others suggest - make sure you backup BEFORE trying this.

HTH,
Randy

Nov 13 '05 #8

"Bob" <ra****@centurytel.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Marko -

We've got the normalization 'mini-lectures' from Joseph and pietlin, et
al.
Let's wait and see if they provide a viable solution as to how to get
out of the problem.

It sounds good when you say it fast, but did you notice that they are
not providing any solutions towards solving the problem?

Bob


Normalization problems are generally much easier to prevent than correct.
;-)

Nov 13 '05 #9
Okay then. Use SPLIT to break out the field into individual values.
then when you get the stupid thing split out, do something like

For intCounter = 0 to UBound(varArray)
'write record to table
rs.Addnew
rs.Fields("SomeField")=varArray(intCounter)
...
rs.Update
Next IntCounter

is that what you wanted, smartass?
Gotta leave him SOMETHING to do! Ya know, exercise his brain.

Marko,
read up on SPLIT and playing with arrays in the VB help. that and
playing with recordsets AddNew and Update and all that stuff. Ho hum.

Happy now Bob?

Nov 13 '05 #10
THANKS ALL!!

Nov 13 '05 #11
Bob wrote:
Marko -

We've got the normalization 'mini-lectures' from Joseph and pietlin,
et al.
Let's wait and see if they provide a viable solution as to how to get
out of the problem.

It sounds good when you say it fast, but did you notice that they are
not providing any solutions towards solving the problem?

Bob


It is difficult to offer exact procedures when you don't have a good
knowledge of the data.

You might also note that assuming your procedure will work (I have no
reason to believe it would not) then Marko would have had that answer prior
to pietlin or my response was posted.

Sometimes just answering a direct question when there is a larger
underlying problem is not doing anyone a favor. It would appear that you
also believe that as you wisely added that making a backup first is a good
idea as it is.

--
Joseph Meehan

Dia duit
Nov 13 '05 #12
rkc
Bob wrote:
Marko -

We've got the normalization 'mini-lectures' from Joseph and pietlin, et
al.
Let's wait and see if they provide a viable solution as to how to get
out of the problem.

It sounds good when you say it fast, but did you notice that they are
not providing any solutions towards solving the problem?


If people would pay more attention to the 'lectures' they wouldn't
have so many problems they couldn't solve. Spoon feeding is a short
term solution. Makes the spoon holder feel special though.
Nov 13 '05 #13

Joseph Meehan wrote:
Sometimes just answering a direct question when there is a larger
underlying problem is not doing anyone a favor.


Yes. Doing so lessens the nature of CDMA as a body of knowledge. When
we search the archives of the newsgroup we could hope to find solutions
based on sound principles. This may be more important for beginners.

Nov 13 '05 #14
Bob wrote:
We've got the normalization 'mini-lectures' from Joseph and pietlin, et
al.
Let's wait and see if they provide a viable solution as to how to get
out of the problem.


There's not a lot of easy fixes. If this is a one time fix, Rick
Fisher's Find and Replace might be of use to Marko:

http://www.rickworld.com/

As to Bob's insistence on letting people continue with poor choices:

Sorry, Bob, but unless you are a spreadsheet designer, what's been said
about normalization simply can't be said enough. There is a bit of a
mental hump most of us have had to get over - we're not quite as
intelligent as you are, you see. The other thing to consider, is if one
just "provides a viable solution" as you are demanding, the concept of
learning about proper techniques, etc, is not served. From the tone of
your response, you are quite happy with letting people happily trot down
poorly chosen paths to oblivion. Presumeably you're one of these people
who don't give any warning and smile watches with amused intensity when
you see a car barrelling towards a washed out bridge.

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto
Nov 13 '05 #15

"Joseph Meehan" <sl*************@hotmail.com> wrote in message
news:4E******************@tornado.ohiordc.rr.com.. .
marko wrote:
Hi!

A have a problem. I have a table containing
ID,Brend,Model,Colour,Price.
The Colour field has colours like: YELLOW/BLACK/RED, YELLOW/RED, BLUE,
BLUE/NAVY/RED/CHARCOAL.
Now i would like to shorten them like this
YELLOW->YEL,BLACK->BLK,WHITE->WHT...
so that the colour field would look like this YEL/BLK/RED and so on.
Please help!

Marko
First note: It certainly looks like your table design is bad.

If you have a record that needs more than one color recorded for it,
almost always you then need a color table related to the original table.

It eliminates a lot of problems. That is the way a database works.

Say after me, Access is a database not a spreadsheet. :-)

This technique is called normalization and there is information on it in the Access help files or almost any book on databases.

--
Joseph Meehan

Dia duit

Going the normalization route and assuming YELLOW/BLACK/RED is different
from YELLOW/RED/BLACK. You could run a make table query exporting all the
combinations of color from your data table, then create a one to many link
from this new color table to color in your old table allowing cascade
updates. Now all you would have to do is edit the new color table to change
the color in the data table.
Nov 13 '05 #16

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

Similar topics

4
867
by: Ka | last post by:
I install a mysql server in default installation with latin charset, but I want to use GBK(a chinese charset), so that I can store and search chinese words directly. so, I download, unpack and...
14
2467
by: Reply Via Newsgroup | last post by:
Folks, Say I have a table, ten columns, ten rows - Each with a word in it. I want to change the values of some/all of the cells in the table via a hyperlink. How do I reference each cell and...
4
2592
by: Richard Cornford | last post by:
For the last couple of months I have been trying to get the next round of updates to the FAQ underway and been being thwarted by a heavy workload (the project I am working on has to be finished an...
3
4738
by: Peter Williams | last post by:
Hi All, I want to write some javascript for a html page which does the following. Imagine that the page contains a table with 2 columns and 3 rows, e.g.: +---+---+ | A | B | +---+---+
7
5433
by: Timo Haberkern | last post by:
Hi there, i have some troubles with my TSearch2 Installation. I have done this installation as described in http://www.sai.msu.su/~megera/oddmuse/index.cgi/Tsearch_V2_compound_words...
8
1987
by: addoty | last post by:
We have a web application that has a lot of large textareas for data collection. We need to track who makes changes, when and what changes were made. Right now I'm storing the entire text in a...
2
1369
by: Peschtra | last post by:
Hello -- Perhaps this is a silly question, but is the word "change" a php or MySql command? I had a script that wouldn't work with the a field called "change" in it, but when I removed that...
7
2564
by: Don NJ | last post by:
First my site name is Sinfullblisslingerie.com. I'm starting this little business to try and make some money on the side. My kids will be going to college in a few years... Anyway, in the past...
130
3229
by: Gianni Mariani | last post by:
Attached example CPP files makes it easier to post code and extract code from posts. It's unimaginable at this time where virtually any news reader is capable of dealing with attachments to stick...
0
7233
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
7135
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
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7410
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...
1
7067
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
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
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.