?
Solved

Query: Movment

Posted on 2011-02-11
9
Medium Priority
?
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 34873597
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
ID: 34873833
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
ID: 34884389
I have solved it and will post my solution if this delete process is stopped.
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 44

Accepted Solution

by:
GRayL earned 2000 total points
ID: 34884410
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
 

Author Comment

by:jbakerstull
ID: 34891545
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
ID: 34891932
Thanks, glad to help.
0
 

Author Comment

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

Author Comment

by:jbakerstull
ID: 34893523
sorry.. Grayl.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 34893554
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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…

765 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