query for last date on multiple records (1 Viewer)

David R

I know a few things...
Local time
Today, 15:17
Joined
Oct 23, 2001
Messages
2,633
Careful. It's #15 if you're in Linear mode, but #11 if you're in Hybrid (and #10 if Threaded, but ugggg).
 

Cirrostratus

Registered User.
Local time
Today, 16:17
Joined
May 16, 2013
Messages
29
If there is two queries, will the form be able to update the data displayed in the second query? I'm thinking not but I'm not 100% sure. :confused:
 

Gismo

Registered User.
Local time
Today, 23:17
Joined
Jun 12, 2017
Messages
1,298
Hi All,

Any reason why my queries and reports will show a text field with Chinese characters instead of the actual description?
Chinese.PNG
 

isladogs

MVP / VIP
Local time
Today, 21:17
Joined
Jan 14, 2017
Messages
18,229
Not sure why you've posted to this old thread.
Unless you've entered these characters, it's a sign of data corruption.
If it's only a couple of records, delete them, compact and recreate the records.
If it's a lot of records, it will be more tricky.

If this answer isn't sufficient, please start a new thread
 

ddbz

New member
Local time
Today, 14:17
Joined
Jan 25, 2023
Messages
2
Hi,

This is an old thread but I have the same problem as OP and am getting errors when using the solutions presented here. I am attempting to filter an ID by the most recent date while including additional information specific to the ID.

My

Example table:
ID Date Frequency
1 1/1/2020 12
1 2/3/2018 48
2 4/23/2018 48
2 7/24/2021 48
3 8/9/2017 12
3 4/23/2018 24

I am trying to return the ID's information for the most recent date:
ID Date Frequency
1 1/1/2020 12
2 7/24/2021 48
3 4/23/2018 24

I have followed the instructions provided by pbaldy but my query is only returning the IDs associated with a single date that is prompted by access upon executing the query.

my two tables are [Active Table] and [Info].

my first query [Active] looks like:
SELECT [Active Table].[ID], Max([Info].[Date]) AS [MaxOfDate1]
FROM [Active Table] INNER JOIN [Info] ON [Active Table].[ID] = [Info].[ID]
GROUP BY [Active Table].[ID];

the second query looks like:
SELECT [Active].[ID], [Info].[Frequency]
FROM [Info] INNER JOIN [Active]
ON ([Info].[ID] = [Active].[ID])
AND ([Info].[Date] = [Active].[Date])

When it's executed the prompt is "enter parameter value" for [Active].[Date] so that it only returns information for IDs with dates equal to the one inputted.


Any help is appreciated!
 

ebs17

Well-known member
Local time
Today, 22:17
Joined
Feb 7, 2020
Messages
1,946
SQL:
SELECT
   E.ID,
   E.Date,
   E.Frequency
FROM
   ExampleTable AS E
      INNER JOIN
         (
            SELECT
               ID,
               MAX(Date) AS MaxDate
            FROM
               ExampleTable
            GROUP BY
               ID
         ) AS SQ
         ON E.ID = SQ.ID
            AND
         E.Date = SQ.MaxDate
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:17
Joined
Aug 30, 2003
Messages
36,126
When it's executed the prompt is "enter parameter value" for [Active].[Date]

As to the error, the Active query doesn't return a field named "Date":

Max([Info].[Date]) AS [MaxOfDate1]
 

ddbz

New member
Local time
Today, 14:17
Joined
Jan 25, 2023
Messages
2
SQL:
SELECT
   E.ID,
   E.Date,
   E.Frequency
FROM
   ExampleTable AS E
      INNER JOIN
         (
            SELECT
               ID,
               MAX(Date) AS MaxDate
            FROM
               ExampleTable
            GROUP BY
               ID
         ) AS SQ
         ON E.ID = SQ.ID
            AND
         E.Date = SQ.MaxDate
Thanks, I'll keep this in my pocket for future reference.

As to the error, the Active query doesn't return a field named "Date":

Max([Info].[Date]) AS [MaxOfDate1]
Hah, not sure how that snuck in. Correcting that fixed the prompt that I previously mentioned. I'm still getting some duplicate line items along with some blanks, but I should be able to filter those out with Is Not Null and by removing duplicates. Thanks for the help.
 

Users who are viewing this thread

Top Bottom