A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Access Query Table: Show value of previous row



 
 
Thread Tools Display Modes
  #1  
Old May 1st, 2008, 11:25 AM posted to microsoft.public.access.forms
Bryn Stevenson
external usenet poster
 
Posts: 1
Default Access Query Table: Show value of previous row

I have created QueryTable from MainTable showing data sorted by StartDateTime. Is there a formula or way of updating the added column QueryTable.PreviousEndDateTime with the value of QueryTable.EndDateTime from the previous row in the query for each record in the query?

The end result is to show the MainTable data in a form by start date/time order whilst alerting that the previous records end date/time field is different to the current records start date/time field. Records in MainTable may be in any order as it stores times on each job for different people.
  #2  
Old May 1st, 2008, 07:16 PM posted to microsoft.public.access.forms
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Access Query Table: Show value of previous row

One way is to add a calculated field. The first query is if all records are
to be treated together.
SELECT Column1, Column2, (SELECT COUNT(*)
FROM [YourTable-4] T1
WHERE T1.Column2 = T.Column2) AS Rank
FROM [YourTable-4] AS T
ORDER BY Column1, Column2;

If you need grouping then use this query instead.
SELECT Q.Group, Q.Points, (SELECT COUNT(*) FROM Product Q1
WHERE Q1.[Group] = Q.[Group]
AND Q1.Points Q.Points)+1 AS Rank
FROM Product AS Q
ORDER BY Q.Group, Q.Points;

Use the one that fits your situation. Then in another query design view
select the above query of choice twice. Access adds a sufix of '_1' to the
second instance of the query.
Join the two queries by clicking on the field names and draging to the
other. Then to see data from two consecutive records add the data field from
the '_1' query and the Rank field also. Use criteria on the '_1' Rank field
of [FirstQuery].[Rank]+1 or [FirstQuery].[Rank]-1 according to whether you
want to look forward or backwards.

--
KARL DEWEY
Build a little - Test a little


"Bryn Stevenson" wrote:

I have created QueryTable from MainTable showing data sorted by StartDateTime. Is there a formula or way of updating the added column QueryTable.PreviousEndDateTime with the value of QueryTable.EndDateTime from the previous row in the query for each record in the query?

The end result is to show the MainTable data in a form by start date/time order whilst alerting that the previous records end date/time field is different to the current records start date/time field. Records in MainTable may be in any order as it stores times on each job for different people.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:52 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.