Solved

delete string from field

Posted on 2014-01-15
6
358 Views
Last Modified: 2014-01-16
Access 2010:

I have  table:
table_images
2 fields:
Primary_ number
Primary_Image

What I need:

In the field "Primary_Image"

If any of the data has a name with a  "_ "<UNDERSCORE>  in it ... like below

3NU39_AW99.JPG

I need it to be changed to

3NU39.JPG

so starting at the  "_ "<UNDERSCORE>   delete the string behind it. but keep the  .jpg

example: again
primary_image
3NU24_AW99.JPG
3NU22_AW99.JPG
24Z173_AS01.JPG
3NU21_AW99.JPG

will be:
primary_image
3NU24.JPG
3NU22.JPG
24Z173.JPG
3NU21.JPG


Thanks
fordraiders
0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39783023
After backing up your table, try something like

UPDATE yourTable
SET Primary_Image = Left([Primary_Image], instr([Primary_Image], "_")-1 & Mid([Primary_Image], instrrev([Primary_Image]), "."))
WHERE instr([Primary_Image], "_") > 0

You might want to start out with:

SELECT [Primary_Image], Left([Primary_Image], instr([Primary_Image], "_")-1 & Mid([Primary_Image], instrrev([Primary_Image]), ".")) as ModPrimImage
WHERE instr([Primary_Image], "_") > 0
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39783145
get a wrong number of arguments error..
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 39783245
a couple of parenthesis issues.  For the SELECT statement try:

SELECT [Primary_Image], Left([Primary_Image], instr([Primary_Image], "_")-1) & Mid([Primary_Image], instrrev([Primary_Image], ".")) as ModPrimImage
WHERE instr([Primary_Image], "_") > 0

for the UPdate it would look like:

UPDATE yourTable
SET Primary_Image = Left([Primary_Image], instr([Primary_Image], "_")-1) & Mid([Primary_Image], instrrev([Primary_Image], "."))
WHERE instr([Primary_Image], "_") > 0
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 50

Expert Comment

by:Gustav Brock
ID: 39783265
You could use this expression:

SET Primary_Image = Left([Primary_Image], InStr([Primary_Image], "_") - 1 & ".jpg"

/gustav
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39783312
always trying to make things easier, aren't you Gustav?

I guess I'm just so used to pulling something off the front, and something off the back that it never occurred to me to do it the simple way (although you forgot the closing paren as well.

@fordraiders

If you are going to do it that way, I would modify the WHERE clause to look something like:

WHERE InStr([Primary_Image], "_") > 0  AND InStr([Primary_Image], ".jpg") > 0

This will make sure you do not inadvertently change the extension of some other image type.
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 39785441
Thanks
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question