Solved

Filter column string with Right function?

Posted on 2013-12-15
21
496 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
  • 10
  • 7
  • 4
21 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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
Comment Utility
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
Comment Utility
Left([Filename],"Len[Filename]-4") is giving me a "Data type mismatch" error?
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
@geekmee2

did you try the query I posted?
0
 

Author Comment

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

Expert Comment

by:Rey Obrero
Comment Utility
what do you mean?

how are you using what  I posted?
0
 

Author Comment

by:geekmee2
Comment Utility
I copy and pasted.... into the criteria field in the query.
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
<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
Comment Utility
Left([Filename],"Len[Filename]-4") should be without the quotes

Kelvin
0
 

Author Comment

by:geekmee2
Comment Utility
Invalid Syntax Error [see screenshot]
InvalidSyntax-Error.jpg
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
<.... 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
Comment Utility
Kelvin, I tried, but the system adds the quotes (?).
0
 
LVL 22

Expert Comment

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

Kelvin
0
 

Author Comment

by:geekmee2
Comment Utility
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 119

Expert Comment

by:Rey Obrero
Comment Utility
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
Comment Utility
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 119

Expert Comment

by:Rey Obrero
Comment Utility
why a B grade ?
0
 

Author Comment

by:geekmee2
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now