A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Help with InStr in a query



 
 
Thread Tools Display Modes
  #1  
Old May 5th, 2010, 10:38 PM posted to microsoft.public.access.queries
cherman
external usenet poster
 
Posts: 25
Default Help with InStr in a query

I have values like "2010 WW14" and "2010 WW7" in a query and I'm trying to
grab the number part to the right of "WW". It will always be a 1 or 2 digit
number and I always want the format to be a number.

I'm currently using Left([WorkWeek2],(InStr(1,[WorkWeek2],"ww")-1)) to grab
the 4-digit year to the left of "WW", but I can't figure out how to alter it
for what I need above. Any suggestions?

Thanks!
  #2  
Old May 5th, 2010, 10:58 PM posted to microsoft.public.access.queries
Dorian
external usenet poster
 
Posts: 542
Default Help with InStr in a query

Try:
mid(WorkWeek2,instr(WorkWeek2,'ww')+2)
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".


"cherman" wrote:

I have values like "2010 WW14" and "2010 WW7" in a query and I'm trying to
grab the number part to the right of "WW". It will always be a 1 or 2 digit
number and I always want the format to be a number.

I'm currently using Left([WorkWeek2],(InStr(1,[WorkWeek2],"ww")-1)) to grab
the 4-digit year to the left of "WW", but I can't figure out how to alter it
for what I need above. Any suggestions?

Thanks!

  #3  
Old May 5th, 2010, 11:07 PM posted to microsoft.public.access.queries
Jerry Whittle
external usenet poster
 
Posts: 4,732
Default Help with InStr in a query

You're working to hard to get the year assuming that the data always looks
like that..

CLng(Val([WorkWeek2]))

Again assuming that the numbers after the WW always start at the 8th
character:

CLng(Mid(WorkWeek2,8))

The CLng function ensures it returns a number and not text.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"cherman" wrote:

I have values like "2010 WW14" and "2010 WW7" in a query and I'm trying to
grab the number part to the right of "WW". It will always be a 1 or 2 digit
number and I always want the format to be a number.

I'm currently using Left([WorkWeek2],(InStr(1,[WorkWeek2],"ww")-1)) to grab
the 4-digit year to the left of "WW", but I can't figure out how to alter it
for what I need above. Any suggestions?

Thanks!

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:30 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.