Solved

Filter column string with Right function?

Posted on 2013-12-15
21
540 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

624 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