We help IT Professionals succeed at work.

Access Update Query to replace values with other values

ggodwin
ggodwin asked
on
Table: DSCNSKPIUPDATE2
Field: Reject

I have data values that resemble the below format.
R0102447 / R0102448

I want to replace the " / " with a ",". I tried with the below code but it does not work.

UPDATE DSCNSkpiUpdate2 SET DSCNSkpiUpdate2.Rank = Replace(Rank," / ",",");

Open in new window


Any ideas how to fix this?
Comment
Watch Question

Something like this should work.  You may have to tweak it a bit to deal with spaces according to what you want the end field to look like:

UPDATE Table1 SET Table1.text1 = Left([text1],InStr([text1],"/")-1) & "," & Mid([text1],InStr([text1],"/")+1);

Open in new window


EDIT: Obviously, the [text1] field name should be replaced with the proper field name for you table.
Top Expert 2016

Commented:
try

UPDATE DSCNSkpiUpdate2 SET DSCNSkpiUpdate2.[Rank] = Replace(Replace([Rank]," ",""),"/","")

this means if "/" is present, replace with , and remove the space
ggodwinQuality Engineer

Author

Commented:
Robert,
Your code actually delected everything in the field.

Rey,
Your code did the same as mine. It appears to work, but then the expected outcome to the tables never changes.
Top Expert 2016

Commented:
can you upload a copy of the db with the table in question.
ggodwinQuality Engineer

Author

Commented:
Ok, I realized that I entered something into the code wrong and it appeared to work.
However, once it did execute it also removed some coma's that needed to stay in place.

Here is the db.

In the reject column i need these format to read as
R0117536,R0117789,R0117123

Instead of any other format. I need to do this so that I can try and use the information you gave me yesterday.
Top Expert 2016

Commented:
where is the db?

<However, once it did execute it also removed some coma's that needed to stay in place.>

the code i posted will never do that..
ggodwinQuality Engineer

Author

Commented:
I must not have uploaded before I posted.
Database11.mdb
Top Expert 2016
Commented:
copy and paste this query and run

UPDATE DSCNSKPIUPDATE2 SET DSCNSKPIUPDATE2.Reject = Replace(Replace([Reject]," ",""),"/",",");
Database11.mdb
When you used my code, I suspect you might have missed renaming something which could have caused the field to be updated to empty.

At any rate, I'm a really old-school Access user... In my day, we didn't have such new-fangled functions as Replace.  :D  Occasionally, my brain decides to program like it's 1989...  Rey's method is the way to go, for sure!
ggodwinQuality Engineer

Author

Commented:
Bingo. Worked perfectly.