Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2015
    Posts
    11

    Need to upadate a field on main form to match a specific record on subform

    I have a main form with Patient demographics and a subform with different messages about that patient. It's a 1 to many relationship. The subform is sorted by date, with the latest message on top.



    What I want to do is create a field on the main form and copy the latest message in it. So when I go back to a different form with continuous view with all he patients listed I can also display the latest message next to the names.

    I'm a doc and not an IT person so not much background in SQL, any knowledge I have of Access is mostly through Google and fine folks like yourselves.
    Hope how I explained it makes sense.

    Thanks.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    it would be 2 queries
    Q1, get the max of date: select [patiendID], MAX([DateOfEvent]) from table

    then with this query get all the records, by joining [patientID] and [DateOfEvent]:
    Q2 =
    SELECT table.PatientID, table.Badge, table.DateOfEvent
    FROM table INNER JOIN Q1 ON (table.DateOfEvent = Q1.MaxOfDateOfEvent) AND (table.PatientID = Q1.PatientID)
    ORDER BY Q1.PatientID;

  3. #3
    Join Date
    Jul 2015
    Posts
    11

    Thanka

    Thanks. I will try it and let you know

  4. #4
    Join Date
    Jul 2015
    Posts
    11
    After researching your method I cam across the DLookUp Function. I seemed a bit easier to understand but it is not working. I made an uncontrolled box on the subform with the data to be the following:

    =DLookUp("[Message]","[Patient Contact Info Table]","[MR#]='" & [Forms]![New Contact Info Subform].[MR#] & "' And [Date of Contact]= '" & [Forms]![New Contact Info Subform].[Latest Date]) & "'"

    [Message] is a memo type field, [Patient Contact Info Table] is where I am looking and want the [MR#] and [Date of Contact] to match the [MR#] and [Latest Date] on the subform

    [Latest Date] is an uncontrolled box with the data value being Max([Date of Contact])

    I get a #Name? error. I'm sure I spelled all the fields correctly

    Can you perhaps see what I may be doing wrong. I'm thinking perhaps DLOOKUP will not work with memo type field?

  5. #5
    Join Date
    Jul 2015
    Posts
    11
    I corrected it a bit, noticing my closing parenthesis was in the wrong place, but still no luck. So now it looks like

    =DLookUp("[Message]","[Patient Contact Info Table]","[MR#]='" & [Forms]![New Contact Info Subform].[MR#] & "' And [Date of Contact]= '" & [Forms]![New Contact Info Subform].[Latest Date] & "'")

    Giving me same error: #Name?

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

Similar Threads

  1. Replies: 2
    Last Post: 06-01-2015, 01:21 PM
  2. Replies: 10
    Last Post: 12-17-2014, 03:31 PM
  3. Replies: 4
    Last Post: 11-06-2014, 05:35 AM
  4. Replies: 6
    Last Post: 08-22-2012, 03:24 AM
  5. Replies: 2
    Last Post: 08-11-2011, 10:02 AM

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