Results 1 to 9 of 9
  1. #1
    ant123 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    14

    Records within 6 months of a date

    Hi All,

    I was hoping you could help me out with a problem. I have a database containing 2 years of healthcare data.

    I have several tables:

    • all_hospital_admissions
    • first_hospital_admissions
    • emergency_department_attendances


    I want to find out how many emergency department attendances a patient has had 6 month previous to their first hospital admission and 6 month post their first hospital admission.

    The date of their first hospital admission is stored in the 'first_hospital_admissions' table as the field name 'date_of_admission'
    The date of emergency department attendances are stored in the 'emergency_department_attendances' table as 'date_of_attendance'
    The patient ID is in all tables (patient_id)



    How do I make a query to check this?

    The other problem is that a patient may have attended the emergency department the day before or on the same day as the first hospital admission. Ideally I would like to remove these emergency department attendances from the count. Is this possible?

    Any help would be greatly appreciated!

    Thank you!

    :-)

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    One approach involves using DMin() domain aggregate function to pull the oldest date value from the admissions table. Something like:

    SELECT * FROM emergency_department_attendances WHERE date_of_attendance > DateAdd("m", -6, DMin("date_of_admission", "first_hospital_admissions", "PatientID=" & [PatientID])) AND date_of_attendance < DateAdd("m", 6, DMin("date_of_admission", "first_hospital_admissions", "PatientID=" & [PatientID]));
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ant123 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    14
    Hi June7 - thank you very much for your reply. I have tried you formula but I can't get it to work.

    Would you mind explaining exactly what each section means to I can work it out. I am trying to get a count of the emergency department attendances 6 months previous and 6 months post the first admission.

    Thank you very much for your help - it is much appreciated

  4. #4
    ant123 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    14
    I think I need something like this to stat with:

    I have joined the tables:

    • first_hospital_admissions
    • emergency_department_attendances


    Then made a query and in the 'date of attendance' field (emergency_department_attendances) I have put:

    >=DateAdd("m",-6,"[date_of_admission]")


    this doesn't work but I think I need something similar...

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Yes, a query join could work if each patient has only 1 record in first_hospital_admissions.

    You want all attendance records that fall between 6 months prior and 6 months after the admission date? criteria under [date of attendance] field:

    > DateAdd("m",-6,"[date_of_admission]") AND < DateAdd("m",6,"[date_of_admission]")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    ant123 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    14
    Hi,

    Thanks for your help. I have tried this formula but it keeps coming up with Data type mismatch in criteria expression

    Any ideas why?

  7. #7
    ant123 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    14
    Im wondering if it because for some patients no record would be returned? (therefore something to do with null values?)

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Maybe. Try:

    Not Is Null AND > DateAdd("m",-6,"[date_of_admission]") AND < DateAdd("m",6,"[date_of_admission]")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    ant123 is offline Novice
    Windows XP Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    14
    Thank you. I have solved it a different way but used some of your formulas! Thanks very much for your help :-)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Get data - 3 months to Date
    By Shilabrow in forum Queries
    Replies: 3
    Last Post: 06-23-2014, 12:04 PM
  2. Calucation of Months between 2 records...
    By tanyalee123 in forum Queries
    Replies: 5
    Last Post: 05-09-2014, 02:45 PM
  3. Replies: 3
    Last Post: 02-23-2014, 02:06 PM
  4. Substracting months to a date
    By ruthib4 in forum Queries
    Replies: 2
    Last Post: 12-21-2011, 10:11 AM
  5. Query criteria, add 5 months to date
    By thart21 in forum Queries
    Replies: 1
    Last Post: 03-29-2010, 05:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums