Solved

Query: Movment

Posted on 2011-02-11
9
263 Views
Last Modified: 2012-09-14
Kind of stuck on this,, need some help..

I have a “is this possible” in an access query question.
Data set below tracks length of in shelter stay.

Client    Program         Entry Date            Exit Date Duration
18         Shelter A       9/2/2010               9/4/2010 2
18         Shelter B       9/7/2010                9/17/2010 10

I need to track a progress called “movement” Movement is defined as when a client leaves a shelter and revisits a different shelter within a seven day period. The previous shelter where the client left within the seven day period is considered liable. Overall, we try to encourage shelters not let clients move around from one shelter to another. I need to mark the record set that fit the criteria with “x” (or some other type of variable).

Client       Program       Entry Date    Exit Date    Duration     Movement
18            Shelter A     8/12/2010    8/22/2010      20
18            Shelter A     9/2/2010      9/4/2010         2                   x
18            Shelter B     9/7/2010      9/21/2010
Movement: IIf(DCount("*","TblMovement","Client=[Client] And Program=""" & [Program] & """ And Entry_Date<=DateAdd('d',7,[Exit_Date])")>0,"x","")

Open in new window

Movement.accdb
0
Comment
Question by:jbakerstull
  • 4
  • 4
9 Comments
 
LVL 77

Expert Comment

by:peter57r
Comment Utility
So you are saying that for each new record, you need to see if there is a record for the same client with a different shelter covering any period in the last seven days?  Is that correct?

And if there are multiple entries with  one or more different shelters - what happens then- do all the previous entries in the last 7 days get marked (presumably some of them already will be marked if there has been a previous 'movement' in the last 7 days.
0
 

Author Comment

by:jbakerstull
Comment Utility
So you are saying that for each new record, you need to see if there is a record for the same client with a different shelter covering any period in the last seven days?  Is that correct?- Yes


And if there are multiple entries with  one or more different shelters - what happens then- do all the previous entries in the last 7 days get marked (presumably some of them already will be marked if there has been a previous 'movement' in the last 7 days:

No, If a client migrates from Shelter A, then to Shelter B and then back to Shelter A, all withing seven days.. then Shelter A (First) and Shelter B will get marked as movement.   I listed below excel formula I'm using along with sample dataset. If client enters and exits Shelter A multiple  times within seven days. Movement does not apply.

I attached the excel file that I"m currently using data's are listed under worksheet called "Movement"

In excel the formula I'm using is =IF(AND(A3=A2,D3<>D2,G3<=7),"Yes"," ")

Shelter-Movement.xlsm
0
 
LVL 44

Expert Comment

by:GRayL
Comment Utility
I have solved it and will post my solution if this delete process is stopped.
0
 
LVL 44

Accepted Solution

by:
GRayL earned 500 total points
Comment Utility
Using this table as tblMovements:

Client      Program      EntryDate      ExitDate
18      ShelterA      2010-08-12      2010-08-22
18      ShelterA      2010-09-02      2010-09-04
18      ShelterB      2010-09-07      2010-09-21

Running this query:

SELECT a.Client, a.Program, a.EntryDate, a.ExitDate, DateDiff("d",a.EntryDate, a.ExitDate) AS Duration, (SELECT Min(b.EntryDate) FROM tblMovements b
WHERE b.EntryDate > a.EntryDate AND DateDiff("d",a.EntryDate, a.ExitDate) < 7 AND b.Program <> a.Program AND b.Client = a.Client) as BadMove
FROM tblMovements  a ORDER BY a.Client, a.EntryDate;

Produced this recordset:

Client      Program      EntryDate      ExitDate      Duration      BadMove
18      ShelterA      2010-08-12      2010-08-22      10      
18      ShelterA      2010-09-02      2010-09-04      2      2010-09-07
18      ShelterB      2010-09-07      2010-09-21      14      
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jbakerstull
Comment Utility
I apologize for not looking at question early. GRayL, thank you. You taught me something that is very useful.
0
 
LVL 44

Expert Comment

by:GRayL
Comment Utility
Thanks, glad to help.
0
 

Author Comment

by:jbakerstull
Comment Utility
Gary.. in the SQL Statement what does a. and b. mean?
0
 

Author Comment

by:jbakerstull
Comment Utility
sorry.. Grayl.
0
 
LVL 44

Expert Comment

by:GRayL
Comment Utility
They are aliases for table names - instead of having to type a very long and compicated name, probably with brackets, I can use the alias in the SELECT and WHERE clauses and only type the name followed by the alias in the FROM clause.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

772 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

11 Experts available now in Live!

Get 1:1 Help Now