Solved

Query: Movment

Posted on 2011-02-11
9
267 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
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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 44

Accepted Solution

by:
GRayL earned 500 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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…

803 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