Results 1 to 3 of 3
  1. #1
    AccessMih is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2022
    Posts
    2

    Tables one with specific Dates the Other With a Range

    Hello All,



    I was recently working on an issue in Excel and discovered that I needed to use Access. Being a complete novice with Access I'm turning to you all for help.

    What I have is three tables:
    1. Patient
    2. Part A - Acute Care
    3. Part D - Prescription

    The Part D - Prescription includes a date where the prescription is filled by a pharmacy.
    The Part A - Acute Care has a date range for when the patient was in a hospital. (Note - there are multiple date ranges for some patients)

    I would like to know if the prescription was filled when the patient was in the hospital. Can you all help me write the query?

    Click image for larger version. 

Name:	Access - Question.PNG 
Views:	21 
Size:	26.3 KB 
ID:	48547

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    Strongly recommend you do the following:

    1. remove spaces and non alphanumeric characters from table and field names - they can cause misleading errors
    2. rename your ID fields to something more relevant such as patientID (I prefer patientPK to identify it as the primary key)
    3. join your tables on the PK field - so your part tables need a patientFK (foreign key field)

    but to answer your question you need a left join between partD and partA tables (return all partD and only partA where there is a match)

    then in the criteria

    PartD.dateOfFill Between PartA.BeginStay and PartA.EndStay OR PartA.ID is Null

  3. #3
    AccessMih is offline Novice
    Windows 10 Office 365
    Join Date
    Aug 2022
    Posts
    2
    Thank you I was able to follow your directions and get the result I was looking for.

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

Similar Threads

  1. Replies: 21
    Last Post: 06-23-2020, 11:45 AM
  2. Replies: 5
    Last Post: 10-02-2017, 02:02 PM
  3. Range of dates not working in vba
    By annmv888 in forum Access
    Replies: 17
    Last Post: 07-14-2016, 11:41 AM
  4. Add a range of dates to a table
    By gemadan96 in forum Programming
    Replies: 3
    Last Post: 06-20-2014, 01:49 PM
  5. Query input dates for range of dates in two fields
    By kagoodwin13 in forum Queries
    Replies: 3
    Last Post: 02-13-2012, 04:25 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