Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Query: Movment

Posted on 2011-02-11
9
Medium Priority
?
282 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
Technology Partners: 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!

 
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

609 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