dbTalk Databases Forums  

Query to rearrange movie-title wording.

comp.databases.ms-access comp.databases.ms-access


Discuss Query to rearrange movie-title wording. in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Peter Jason
 
Posts: n/a

Default Re: Query to rearrange movie-title wording. - 06-25-2011 , 12:39 AM






On Sat, 25 Jun 2011 14:47:37 +1000, Peter Jason <pj (AT) jostle (DOT) com> wrote:

Quote:
On Fri, 24 Jun 2011 14:32:12 -0400, "Bob Barrows"
reb01501 (AT) NOSPAMyahoo (DOT) com> wrote:

Peter Jason wrote:
For the "The" case I use:
Expr1: Replace([MovieNameEnglish],"The ","")

That will replace any occurence of "The" with an empty space, resulting in
titles like "Phantom of Opera" and "Meet Fockers"

And for the "A" case I use:
Expr2: Replace([Expr1],"A ","")


Same objection. Personally, I would create a VBA function to do this but it
is possible with expressions:

Expr1: iif(left([MovieNameEnglish],4)="The ",Mid([MovieNameEnglish],5) & ",
The", [MovieNameEnglish])

Same idea for Expr2.

Question: should you move "An " to the end of the title as well ("An Affair
to Remember")?


Thanks, but I can't get it to work: I type the above as:

Expr4: iif(left([MovieNameEnglish],4)="The ",Mid([MovieNameEnglish],5)
& ", The", [MovieNameEnglish])

The query grid acceps it, but nothing shows up when the query is run.

Peter
Sorry, false alarm. There was a Cr in you expression that had to be
removed.

I used:
1/ To move the "And":

Expr5: IIf(Left([MovieNameEnglish],4)="The ",Mid([MovieNameEnglish],5)
& ", The",[MovieNameEnglish])

2/ To move the "A":

Expr6: IIf(Left([Expr5],2)="A ",Mid([Expr5],3) & ", A",[Expr5])


Unfortunately when I run the query and the report based on it, Access
throws up a blank parameter box which requires two Cr for the query
and report to run.

Any idea what causes this?

Regards, Peter

Reply With Quote
  #12  
Old   
Bob Barrows
 
Posts: n/a

Default Re: Query to rearrange movie-title wording. - 06-25-2011 , 07:02 AM






"Peter Jason" <pj (AT) jostle (DOT) com> wrote

Quote:
Same objection. Personally, I would create a VBA function to do this but
it
is possible with expressions:

Expr1: iif(left([MovieNameEnglish],4)="The ",Mid([MovieNameEnglish],5) &
",
The", [MovieNameEnglish])

Unfortunately when I run the query and the report based on it, Access
throws up a blank parameter box which requires two Cr for the query
and report to run.

You must have failed to remove the CRs when entering your expressions. This
is why I would have used a VBA function to do this - VBA code can be
formatted to avoid the chars/line limit imposed by newsreaders. Here is what
such a function would look like.

1. If you have no modules in the Modules tab of your database window, click
the New button to create a new one - you can keep the name Module1 if you
want, or enter a name like MyFunctions if you desire. Otherwise, doubleclick
one of the existing modules to open it.

2. In the resulting code window enter:

Public Function GetSortableTitle(ByVal pTitle As String) _
As String
if len(pTitle)>0 then
if left(pTitle,2)="A " Then
pTitle=Mid(pTitle,3) & ", A"
end if
if left(pTitle,3)="An " Then
pTitle=Mid(pTitle,4) & ", An"
end if
if left(pTitle,4)="The " Then
pTitle=Mid(pTitle,5) & ", The"
end if
end if
SortableTitle=pTitle
End Function

In your query, use:
SortableTitle: GetSortableTitle([MovieNameEnglish])

Reply With Quote
  #13  
Old   
John Spencer
 
Posts: n/a

Default Re: Query to rearrange movie-title wording. - 06-25-2011 , 10:38 AM



If you do it in the query, you need to nest the IIF statements all in one
expression. That expression might look like the following - all one line.

IIf([MovieNameEnglish] Like "The *", Mid([MovieNameEnglish],5) & ", The"
, IIF([MovieNameEnglish] Like "A *", Mid([MovieNameEnglish],3) & ", A")
, IIF([MovieNameEnglish] Like "An *", Mid([MovieNameEnglish],4) & ", An"
, [MovieNameEnglish])))

Note that the last choice was to return MovieNameEnglish in the case that it
did not start with The, An, or A. Hope this helps. As noted by Bob Barrows
you **might** be better off using a custom VBA function to do this.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

On 6/25/2011 1:39 AM, Peter Jason wrote:
Quote:
IIf(Left([MovieNameEnglish],4)="The ",Mid([MovieNameEnglish],5)
& ", The",[MovieNameEnglish])

Reply With Quote
  #14  
Old   
zuckermanf@gmail.com
 
Posts: n/a

Default Re: Query to rearrange movie-title wording. - 06-28-2011 , 12:43 AM



A different approach.....

I understand that you remove the words "A" and "The" in order to make
sorting easier. Why not leave the title alone and create a query with
one additional field called Title2. Title2 would be created by
removing the selected words. Then, in your sorting and other
functions, use the Title2 field. And when you want to use the true
title, you still have the untouched field.

Fred Zuckerman



On Jun 25, 8:38*am, John Spencer <JSPEN... (AT) Hilltop (DOT) umbc> wrote:
Quote:
If you do it in the query, you need to nest the IIF statements all in one
expression. *That expression might look like the following - all one line.

IIf([MovieNameEnglish] Like "The *", Mid([MovieNameEnglish],5) & ", The"
, IIF([MovieNameEnglish] Like "A *", Mid([MovieNameEnglish],3) & ", A")
, IIF([MovieNameEnglish] Like "An *", Mid([MovieNameEnglish],4) & ", An"
, [MovieNameEnglish])))

Note that the last choice was to return MovieNameEnglish in the case thatit
did not start with The, An, or A. *Hope this helps. *As noted by Bob Barrows
you **might** be better off using a custom VBA function to do this.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

On 6/25/2011 1:39 AM, Peter Jason wrote:



IIf(Left([MovieNameEnglish],4)="The ",Mid([MovieNameEnglish],5)
& *", The",[MovieNameEnglish])- Hide quoted text -

- Show quoted text -

Reply With Quote
  #15  
Old   
Bob Barrows
 
Posts: n/a

Default Re: Query to rearrange movie-title wording. - 06-28-2011 , 05:54 AM



I believe that's exactly what he's doing. See the very first post in this
thread where he says "This is used as a
source for a report."

zuckermanf (AT) gmail (DOT) com wrote:
Quote:
A different approach.....

I understand that you remove the words "A" and "The" in order to make
sorting easier. Why not leave the title alone and create a query with
one additional field called Title2. Title2 would be created by
removing the selected words. Then, in your sorting and other
functions, use the Title2 field. And when you want to use the true
title, you still have the untouched field.

Fred Zuckerman


Reply With Quote
Reply




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 On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.