Solved

Query: Movment

Posted on 2011-02-11
9
273 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

690 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