Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / March 2007

Tip: Looking for answers? Try searching our database.

access query trouble-HELP!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
schoenman@gmail.com - 28 Mar 2007 06:18 GMT
Hi all,

I have been trying to figure this out for the last 14 hours and am
making almost no progress. Any help is GREATLY appreciated.

I have two tables: one is a large table of parliamentarians, dates of
their speeches in parliament, their party and other such info (many
thousands of rows). The other table is a list of 11 coalition
governments, dates in power and the parties that supported them (as
shown below).

What I would like to do is run a query that adds a column to table 1,
which stores information about whether a speaker's party was a member
of the governing coalition on the date of the speech. If yes, it
should return the number associated with the coalition government (a
number from 1-11), otherwise a "0".

So, I understand that I need to write an expression that checks if the
date of a speech falls in between the date range of a government AND
if the speaker's party was in the coalition on that date. I have tried
writing an expression using the SWITCH or IIF functions, to no avail.
Although I tried many different things, the latest looks like this:

Coalition:Iif(( [Speeches March 27]![Date] =  Between [Coalitions]!
[Date Begins] And [Coalitions]![Date Ends] ) AND ([PartyAbbrev] =
[Coalitions]![Party1] OR [PartyAbbrev] =  [Coalitions]![Party2] OR
[PartyAbbrev] = [Coalitions]![Party3] OR [PartyAbbrev]= [Coalitions]!
[Party4]) , [Coalitions]![Coalition Number],"")

In particular, the problem seems to be that Access disregards the
second set of criteria (Party) and just works off the date ranges,
leaving me with numbers in every cell (since all the dates fall within
one of the ranges). Not sure what I am doing wrong. Any help or
pointers are MUCH appreciated. Thanks in advance,

Roger

Table 1
MPName        DateofVote   Party.....
John John       1/1/02           ABC
Mark Mark      1/8/03           DEF
.
.

Table 2
Govt    StartDate   EndDate   Party1   Party2   Party3
1         1/1/95        1/1/98       ABC     XYZ
2         2/1/98        1/1/00       DEF     HGJ
.
.
John Spencer - 28 Mar 2007 17:05 GMT
You could try the following expression (note that I changed "= Between ..."
to "Between ..." and combined the OR into an IN clause.

Coalition:  IIF( [Speeches March 27]![Date] Between [Coalitions]![Date
Begins] And [Coalitions]![Date Ends]
AND [PartyAbbrev] IN
([Coalitions]![Party1],[Coalitions]![Party2],[Coalitions]![Party3],[Coalitions]![Party4])
,
[Coalitions]![Coalition Number], 0)

Perhaps the following query will work for you - Note that I guessed at table
and field names since they don't seem to be consistent in your message.
They appear to be one thing in the IIF statement and something else in your
sample records.  It doesn't return zero for those that weren't in the
government

SELECT MPName, Party, [Date], GOVT
FROM [Speeches March 27] as A INNER JOIN [Coalitions] as B
ON A.[Date] >= B.[Date Begins]AND
      A.[Date]<= B.[Date Ends]
WHERE A.PartyAbbrev in (B.Party1,B.Party2,B.Party3,B.Party4)

Signature

John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.

> Hi all,
>
[quoted text clipped - 44 lines]
> 1         1/1/95        1/1/98       ABC     XYZ
> 2         2/1/98        1/1/00       DEF     HGJ
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.