WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Display most recent comment in report

 
Goto page 1, 2
   Home -> Office other -> Getting Started RSS
Next:  football  
Author Message
mcbaker

External


Since: Aug 05, 2008
Posts: 13



(Msg. 1) Posted: Fri Aug 29, 2008 7:19 am
Post subject: Display most recent comment in report
Archived from groups: microsoft>public>access>gettingstarted (more info?)

Hello,

I have a report based on a table called projects, and I wish to include only
the most recent record from a subform called communications. I figure this
would be done by a query...but maybe not?

Any help would be appreciated!

BTW, thanks to those who helped me with my last problem with the Primary and
foreign keys. All is good there now.

--
Judy
Back to top
Login to vote
Klatuu

External


Since: Apr 06, 2005
Posts: 2923



(Msg. 2) Posted: Fri Aug 29, 2008 7:46 am
Post subject: RE: Display most recent comment in report [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

How do you know which is the most recent record?
--
Dave Hargis, Microsoft Access MVP


"mcbaker" wrote:

> Hello,
>
> I have a report based on a table called projects, and I wish to include only
> the most recent record from a subform called communications. I figure this
> would be done by a query...but maybe not?
>
> Any help would be appreciated!
>
> BTW, thanks to those who helped me with my last problem with the Primary and
> foreign keys. All is good there now.
>
> --
> Judy
Back to top
Login to vote
mcbaker

External


Since: Aug 05, 2008
Posts: 13



(Msg. 3) Posted: Fri Aug 29, 2008 8:22 am
Post subject: RE: Display most recent comment in report [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I have a date field in the table which I made visible in the subform.
--
Judy


"Klatuu" wrote:

> How do you know which is the most recent record?
> --
> Dave Hargis, Microsoft Access MVP
>
>
> "mcbaker" wrote:
>
> > Hello,
> >
> > I have a report based on a table called projects, and I wish to include only
> > the most recent record from a subform called communications. I figure this
> > would be done by a query...but maybe not?
> >
> > Any help would be appreciated!
> >
> > BTW, thanks to those who helped me with my last problem with the Primary and
> > foreign keys. All is good there now.
> >
> > --
> > Judy
Back to top
Login to vote
Klatuu

External


Since: Apr 06, 2005
Posts: 2923



(Msg. 4) Posted: Fri Aug 29, 2008 8:50 am
Post subject: RE: Display most recent comment in report [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Okay, what you can do is create a totals query that returns the records with
the Max value for that date field. You will need to include the field that
would join it to the main table to include it in the report's recordset.

It would be something like:

SELECT RecID, CommentsField FROM MyTable WHERE RecID IN (SELECT RecID,
Max([DateFieldName]) AS MostRecent FROM MyTable GROUP BY RecID);
--
Dave Hargis, Microsoft Access MVP


"mcbaker" wrote:

> I have a date field in the table which I made visible in the subform.
> --
> Judy
>
>
> "Klatuu" wrote:
>
> > How do you know which is the most recent record?
> > --
> > Dave Hargis, Microsoft Access MVP
> >
> >
> > "mcbaker" wrote:
> >
> > > Hello,
> > >
> > > I have a report based on a table called projects, and I wish to include only
> > > the most recent record from a subform called communications. I figure this
> > > would be done by a query...but maybe not?
> > >
> > > Any help would be appreciated!
> > >
> > > BTW, thanks to those who helped me with my last problem with the Primary and
> > > foreign keys. All is good there now.
> > >
> > > --
> > > Judy
Back to top
Login to vote
mcbaker

External


Since: Aug 05, 2008
Posts: 13



(Msg. 5) Posted: Fri Aug 29, 2008 9:39 am
Post subject: RE: Display most recent comment in report [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I'm getting an error message on the query. It says that there is an extra )
in the expression.

And, let me make sure I have the correct fields:

Main table is Projects, primary key ProjectsID.
Sub table (form) is Communications Log, primary key NoteID, with a matching
Project field. The field with the information I want to display is called
Notes. I also have one called Date. I would like to display both Date and
Notes.

In the relationship table, I made ProjectID in the Projects table the
Primary key, and the Project field in the Communications Log as the foreign
key. It is a one to many relationship


So, I have written the query like this:
SELECT Project, NoteField FROM Communications Log WHERE Project IN (SELECT
Project, Max([DateFieldName]) AS MostRecent FROM Communications Log GROUP BY
Project)

Any idea what I am doing wrong?
--
Judy


"Klatuu" wrote:

> Okay, what you can do is create a totals query that returns the records with
> the Max value for that date field. You will need to include the field that
> would join it to the main table to include it in the report's recordset.
>
> It would be something like:
>
> SELECT RecID, CommentsField FROM MyTable WHERE RecID IN (SELECT RecID,
> Max([DateFieldName]) AS MostRecent FROM MyTable GROUP BY RecID);
> --
> Dave Hargis, Microsoft Access MVP
>
>
> "mcbaker" wrote:
>
> > I have a date field in the table which I made visible in the subform.
> > --
> > Judy
> >
> >
> > "Klatuu" wrote:
> >
> > > How do you know which is the most recent record?
> > > --
> > > Dave Hargis, Microsoft Access MVP
> > >
> > >
> > > "mcbaker" wrote:
> > >
> > > > Hello,
> > > >
> > > > I have a report based on a table called projects, and I wish to include only
> > > > the most recent record from a subform called communications. I figure this
> > > > would be done by a query...but maybe not?
> > > >
> > > > Any help would be appreciated!
> > > >
> > > > BTW, thanks to those who helped me with my last problem with the Primary and
> > > > foreign keys. All is good there now.
> > > >
> > > > --
> > > > Judy
Back to top
Login to vote
Klatuu

External


Since: Apr 06, 2005
Posts: 2923



(Msg. 6) Posted: Fri Aug 29, 2008 9:47 am
Post subject: RE: Display most recent comment in report [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

The most obvious thing I see is you are using spaces in your names (which you
should not) and not enclosing the name in brackets.

SELECT Project, NoteField FROM [Communications Log] WHERE Project IN (SELECT
Project, Max([DateFieldName]) AS MostRecent FROM [Communications Log] GROUP
BY Project)

Also, you should not use Date as a field name. It is a reserved word. You
should not use any reserved words like Date, Name, Month, Year, etc. Access
can get confused over what you are referring to.
--
Dave Hargis, Microsoft Access MVP


"mcbaker" wrote:

> I'm getting an error message on the query. It says that there is an extra )
> in the expression.
>
> And, let me make sure I have the correct fields:
>
> Main table is Projects, primary key ProjectsID.
> Sub table (form) is Communications Log, primary key NoteID, with a matching
> Project field. The field with the information I want to display is called
> Notes. I also have one called Date. I would like to display both Date and
> Notes.
>
> In the relationship table, I made ProjectID in the Projects table the
> Primary key, and the Project field in the Communications Log as the foreign
> key. It is a one to many relationship
>
>
> So, I have written the query like this:
> SELECT Project, NoteField FROM Communications Log WHERE Project IN (SELECT
> Project, Max([DateFieldName]) AS MostRecent FROM Communications Log GROUP BY
> Project)
>
> Any idea what I am doing wrong?
> --
> Judy
>
>
> "Klatuu" wrote:
>
> > Okay, what you can do is create a totals query that returns the records with
> > the Max value for that date field. You will need to include the field that
> > would join it to the main table to include it in the report's recordset.
> >
> > It would be something like:
> >
> > SELECT RecID, CommentsField FROM MyTable WHERE RecID IN (SELECT RecID,
> > Max([DateFieldName]) AS MostRecent FROM MyTable GROUP BY RecID);
> > --
> > Dave Hargis, Microsoft Access MVP
> >
> >
> > "mcbaker" wrote:
> >
> > > I have a date field in the table which I made visible in the subform.
> > > --
> > > Judy
> > >
> > >
> > > "Klatuu" wrote:
> > >
> > > > How do you know which is the most recent record?
> > > > --
> > > > Dave Hargis, Microsoft Access MVP
> > > >
> > > >
> > > > "mcbaker" wrote:
> > > >
> > > > > Hello,
> > > > >
> > > > > I have a report based on a table called projects, and I wish to include only
> > > > > the most recent record from a subform called communications. I figure this
> > > > > would be done by a query...but maybe not?
> > > > >
> > > > > Any help would be appreciated!
> > > > >
> > > > > BTW, thanks to those who helped me with my last problem with the Primary and
> > > > > foreign keys. All is good there now.
> > > > >
> > > > > --
> > > > > Judy
Back to top
Login to vote
Ken Sheridan

External


Since: Jul 16, 2005
Posts: 2999



(Msg. 7) Posted: Fri Aug 29, 2008 2:56 pm
Post subject: RE: Display most recent comment in report [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Judy:

The IN operator can only be used where the subquery returns one column;
yours returns two It should be:

SELECT Project, Notes, [Date]
FROM [Communications Log] AS CL1
WHERE [Date] =
(SELECT MAX([Date])
FROM [Communications Log] AS CL2
WHERE CL2.Project = CL1.Project);

Note how the two instances of the table are differentiated by the aliases
CL1 and CL2 to enable the subquery to be correlated with the outer query.
The subquery returns the MAX (latest) date where the value in the Project
column equals the value in the Project column in the current row of the outer
query, so by restricting the outer query to those rows where the date equals
the value returned by the subquery, the outer query returns only those rows
with the latest date per project.

I'd strongly advise against using Date as a column name. It’s the name of a
built in function so should be avoided for object names. Use something
specific like NoteDate or DateReceived.

Ken Sheridan
Stafford, England

"mcbaker" wrote:

> I'm getting an error message on the query. It says that there is an extra )
> in the expression.
>
> And, let me make sure I have the correct fields:
>
> Main table is Projects, primary key ProjectsID.
> Sub table (form) is Communications Log, primary key NoteID, with a matching
> Project field. The field with the information I want to display is called
> Notes. I also have one called Date. I would like to display both Date and
> Notes.
>
> In the relationship table, I made ProjectID in the Projects table the
> Primary key, and the Project field in the Communications Log as the foreign
> key. It is a one to many relationship
>
>
> So, I have written the query like this:
> SELECT Project, NoteField FROM Communications Log WHERE Project IN (SELECT
> Project, Max([DateFieldName]) AS MostRecent FROM Communications Log GROUP BY
> Project)
>
> Any idea what I am doing wrong?
> --
> Judy
>
>
> "Klatuu" wrote:
>
> > Okay, what you can do is create a totals query that returns the records with
> > the Max value for that date field. You will need to include the field that
> > would join it to the main table to include it in the report's recordset.
> >
> > It would be something like:
> >
> > SELECT RecID, CommentsField FROM MyTable WHERE RecID IN (SELECT RecID,
> > Max([DateFieldName]) AS MostRecent FROM MyTable GROUP BY RecID);
> > --
> > Dave Hargis, Microsoft Access MVP
> >
> >
> > "mcbaker" wrote:
> >
> > > I have a date field in the table which I made visible in the subform.
> > > --
> > > Judy
> > >
> > >
> > > "Klatuu" wrote:
> > >
> > > > How do you know which is the most recent record?
> > > > --
> > > > Dave Hargis, Microsoft Access MVP
> > > >
> > > >
> > > > "mcbaker" wrote:
> > > >
> > > > > Hello,
> > > > >
> > > > > I have a report based on a table called projects, and I wish to include only
> > > > > the most recent record from a subform called communications. I figure this
> > > > > would be done by a query...but maybe not?
> > > > >
> > > > > Any help would be appreciated!
> > > > >
> > > > > BTW, thanks to those who helped me with my last problem with the Primary and
> > > > > foreign keys. All is good there now.
> > > > >
> > > > > --
> > > > > Judy
Back to top
Login to vote
mcbaker

External


Since: Aug 05, 2008
Posts: 13



(Msg. 8) Posted: Sat Aug 30, 2008 5:04 pm
Post subject: RE: Display most recent comment in report [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks for the clarification. However, I continue to get an error message:

Syntax error (missing operator) in query expression SELECT Project, Notes,
[NoteDate]
FROM [Communications Log] AS CL1
WHERE [NoteDate] =
(SELECT MAX([Date])
FROM [Communications Log] AS CL2
WHERE CL2.Project = CL1.Project);

Please note that I changed the name of the "Date" field to NoteDate

I'm sure this is a simple fix, once I find what I am missing...thank you to
everyone kind enough to help me out here.

Judy

--
Judy


"Ken Sheridan" wrote:

> Judy:
>
> The IN operator can only be used where the subquery returns one column;
> yours returns two It should be:
>
> SELECT Project, Notes, [Date]
> FROM [Communications Log] AS CL1
> WHERE [Date] =
> (SELECT MAX([Date])
> FROM [Communications Log] AS CL2
> WHERE CL2.Project = CL1.Project);
>
> Note how the two instances of the table are differentiated by the aliases
> CL1 and CL2 to enable the subquery to be correlated with the outer query.
> The subquery returns the MAX (latest) date where the value in the Project
> column equals the value in the Project column in the current row of the outer
> query, so by restricting the outer query to those rows where the date equals
> the value returned by the subquery, the outer query returns only those rows
> with the latest date per project.
>
> I'd strongly advise against using Date as a column name. It’s the name of a
> built in function so should be avoided for object names. Use something
> specific like NoteDate or DateReceived.
>
> Ken Sheridan
> Stafford, England
>
> "mcbaker" wrote:
>
> > I'm getting an error message on the query. It says that there is an extra )
> > in the expression.
> >
> > And, let me make sure I have the correct fields:
> >
> > Main table is Projects, primary key ProjectsID.
> > Sub table (form) is Communications Log, primary key NoteID, with a matching
> > Project field. The field with the information I want to display is called
> > Notes. I also have one called Date. I would like to display both Date and
> > Notes.
> >
> > In the relationship table, I made ProjectID in the Projects table the
> > Primary key, and the Project field in the Communications Log as the foreign
> > key. It is a one to many relationship
> >
> >
> > So, I have written the query like this:
> > SELECT Project, NoteField FROM Communications Log WHERE Project IN (SELECT
> > Project, Max([DateFieldName]) AS MostRecent FROM Communications Log GROUP BY
> > Project)
> >
> > Any idea what I am doing wrong?
> > --
> > Judy
> >
> >
> > "Klatuu" wrote:
> >
> > > Okay, what you can do is create a totals query that returns the records with
> > > the Max value for that date field. You will need to include the field that
> > > would join it to the main table to include it in the report's recordset.
> > >
> > > It would be something like:
> > >
> > > SELECT RecID, CommentsField FROM MyTable WHERE RecID IN (SELECT RecID,
> > > Max([DateFieldName]) AS MostRecent FROM MyTable GROUP BY RecID);
> > > --
> > > Dave Hargis, Microsoft Access MVP
> > >
> > >
> > > "mcbaker" wrote:
> > >
> > > > I have a date field in the table which I made visible in the subform.
> > > > --
> > > > Judy
> > > >
> > > >
> > > > "Klatuu" wrote:
> > > >
> > > > > How do you know which is the most recent record?
> > > > > --
> > > > > Dave Hargis, Microsoft Access MVP
> > > > >
> > > > >
> > > > > "mcbaker" wrote:
> > > > >
> > > > > > Hello,
> > > > > >
> > > > > > I have a report based on a table called projects, and I wish to include only
> > > > > > the most recent record from a subform called communications. I figure this
> > > > > > would be done by a query...but maybe not?
> > > > > >
> > > > > > Any help would be appreciated!
> > > > > >
> > > > > > BTW, thanks to those who helped me with my last problem with the Primary and
> > > > > > foreign keys. All is good there now.
> > > > > >
> > > > > > --
> > > > > > Judy
>
Back to top
Login to vote
Display posts from previous:   
       Home -> Office other -> Getting Started All times are: Eastern Time (US & Canada) (change)
Goto page 1, 2
Page 1 of 2

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
 Office
  Office Other
 Security
 WinRAR
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET