Solved

Filter column string with Right function?

Posted on 2013-12-15
21
532 Views
Last Modified: 2013-12-15
I am trying to strip off the .jpg extension in my filenames... but the query I am using returns nothing.

How do I filter a column full of serialized photo file names with Right function?

I have a column full of filenames of serialized photos:
[FileName]
d3x_6013.jpg
d3x_6014.jpg
d3x_6015.jpg

I simply want to remove the .jpg extension using the Right function.

When I use the following formula in a query using the Right function in the criteria field it returns nothing?

Right([FileName],8)

(Ideally, I would like a query that would also strip out the "d3x" off the beginning of the filename as well, so I am left with just the numbers.)

-Greg
0
Comment
Question by:geekmee2
[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
  • 10
  • 7
  • 4
21 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39720711
try this query

select [FileName], val(mid([FileName],5))
from tablex


or this

select [FileName], mid([FileName],5,Instr([FileName],".")-5)
from tablex
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39720719
The right function returns the selected number of characters that you passed in , count in from the right. RIGHT([FileName],4) would give you .jpg

If the filename is always in the format you suggest, then LEFT([Filename],Len(Filename]-4) will give you what you want.


Kelvin
0
 

Author Comment

by:geekmee2
ID: 39720741
Left([Filename],"Len[Filename]-4") is giving me a "Data type mismatch" error?
0
Technology Partners: 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39720742
@geekmee2

did you try the query I posted?
0
 

Author Comment

by:geekmee2
ID: 39720745
Yes, Capricorn.... It gave me an error of Invalid syntax or I needed to put quotes around text.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39720747
what do you mean?

how are you using what  I posted?
0
 

Author Comment

by:geekmee2
ID: 39720748
I copy and pasted.... into the criteria field in the query.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39720750
<I copy and pasted>  where did you paste ?

post what ever you have going.


<.... into the criteria field in the query. > that is not correct
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39720757
Left([Filename],"Len[Filename]-4") should be without the quotes

Kelvin
0
 

Author Comment

by:geekmee2
ID: 39720759
Invalid Syntax Error [see screenshot]
InvalidSyntax-Error.jpg
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39720761
<.... into the criteria field in the query. > that is not correct

it should be like this


            field    [FileName]  |  val(mid([FileName],5))
table name                         |
criteria



x
0
 

Author Comment

by:geekmee2
ID: 39720765
Kelvin, I tried, but the system adds the quotes (?).
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39720769
Ah should be
Left([Filename],Len([Filename])-4)

Kelvin
0
 

Author Comment

by:geekmee2
ID: 39720771
Capricorn1:  Yes, that worked!.... Thank you for the screenshot.

But please help me understand what this formula is doing?

Was I using the wrong function (Left) to accomplish this in the criteria field?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39720776
Left("d3x_6013.jpg",4) will give you  d3x_

Left("d3x_6013.jpg",Len("d3x_6013.jpg")-4)    > will give you  6013.jpg



Mid("d3x_6013.jpg",5) will give you 6013.jpg

Val(6013.jpg)  will give you  6013

so the combination  

val(Mid("d3x_6013.jpg",5) ) will give 6013


better look in the VBA help file  for the Left, Mid, Right function and the VAL function
0
 

Author Comment

by:geekmee2
ID: 39720787
Ok. so the the Mid function returns results to the Val function, and the Val function acts on what was passed to it, and gives me the final desired result.

So the Left function only gets me part of the way there, or my first request.

But still don't understand why the Left function in the criteria field was returning a blank set of results?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39720796
why a B grade ?
0
 

Author Comment

by:geekmee2
ID: 39720810
I did offer 500 points...for the answer, which you did give, promptly.

I still had questions, but you did offer extended breakdown of the other functions, and you did point me to additional resources, VBA helpfile.

I can change it to an A if you would like, I try and reserve A for exceptional effort.

As a trainer, I have feel the value of an answer is tailoring the answer to the knowledge level of the student... which I feel your screenshot accomplished.

How do go about revising the grade to an A?
0
 

Author Comment

by:geekmee2
ID: 39720816
I am happy to change it to an A if you like...

But in reviewing the posting, originally I was trying to use the Right function to achieve my goal.  You gave me another solution, which was better.

But for me, an A means there was no way to improve on the delivery of the answer.  
Here my gut reaction was "what am I doing wrong."   While the answer was correct, I was still left with the question of what I was doing wrong.

For me, an A would have helped me understand the flaw of my approach, which would have expanded my knowledge and understanding of using your (a better) approach.

Hope that helps.

-Greg
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39720818
Hmmmm,

This is a site for answers - not a training site, although many experts such as Capricorn1 so the extra mile and offers extra advice and reasoning. An A is usually given for a answer that fully solves the problem (whether or not training is provided).

Kelvin
0
 

Author Comment

by:geekmee2
ID: 39720822
Understood.... My bad.  I guess I need to manage my expectations.

I can change the grade to an A.... for it was very correct.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

733 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