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 » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Where do I Calculate Previous Record?



 
 
Thread Tools Display Modes
  #1  
Old July 7th, 2009, 01:09 PM posted to microsoft.public.access
Peter Noneley
external usenet poster
 
Posts: 13
Default Where do I Calculate Previous Record?

Hello,

I have a database with two tables, which keeps track of historical
patient appointment dates.

The tables both have AutoNumber key fields, PatID and AppID, and are
related on PatID.

I have a Form that shows an individual patient with their appointments
on a subform.

What I need now is to calculate how many days between each of their
appointments.

PAT ID 100
APPOINTMENT DAYS BETWEEN
01-JAN-09 0
08-JAN-09 7
20-JAN-09 11
23-JAN-09 2

I would like this calculation to show on a Form and Report.

What I have already tried.
- I looked on the web for info on calculating on previous records.
- It seems that Domain Aggregate functions are what I needed to use,
but I could not get them
to work as they looked at the key field AppID. The AppID is
incremented each time any appointment
is created, so although it is sequential, it is not sequential for
each specific patient.
- I looked at VBA code that tried to do the same thing, but it still
did not take into account
that I wanted to look at the previous record for a specific patient,
rather than the previous
record in the list of appointments.
- I then started looking at Running Sum in Queries, at this stage I
realised I was out of my
depth. (Which is not very deep at all!)


My questions:
(1) Do I do the calculation in a Query first, then base the Form /
Report on the Query?
(2) How do I do the calculation?

Any help will be appreciated.

Thanks.


Tables
tblPatient
PATID, Autonumber, Key

tblAppointment
APPID, Autonumber, key
PATID, Number
APPDATE, Date
  #2  
Old July 7th, 2009, 02:09 PM posted to microsoft.public.access
BruceM[_4_]
external usenet poster
 
Posts: 558
Default Where do I Calculate Previous Record?

Assuming PatID is the linking field between the main records and the
individual appointment records, make a query (I am assuming the table with
the appointment information is named tblAppt, but change it as needed)
including ApptDate (the appointment date field) and PatID. I would add
AppID also, as it is the key field, but it is not used in the expression.

At the top of a blank column in query design view (use a name of your choice
instead of SinceLast, if you like):

SinceLast: Nz(DateDiff("d",DMax("ApptDate","tblAppt","PatID = " & [PatID] &
" AND
ApptDate #" & [ApptDate] & "#"),[ApptDate]),0)

"Peter Noneley" wrote in message
...
Hello,

I have a database with two tables, which keeps track of historical
patient appointment dates.

The tables both have AutoNumber key fields, PatID and AppID, and are
related on PatID.

I have a Form that shows an individual patient with their appointments
on a subform.

What I need now is to calculate how many days between each of their
appointments.

PAT ID 100
APPOINTMENT DAYS BETWEEN
01-JAN-09 0
08-JAN-09 7
20-JAN-09 11
23-JAN-09 2

I would like this calculation to show on a Form and Report.

What I have already tried.
- I looked on the web for info on calculating on previous records.
- It seems that Domain Aggregate functions are what I needed to use,
but I could not get them
to work as they looked at the key field AppID. The AppID is
incremented each time any appointment
is created, so although it is sequential, it is not sequential for
each specific patient.
- I looked at VBA code that tried to do the same thing, but it still
did not take into account
that I wanted to look at the previous record for a specific patient,
rather than the previous
record in the list of appointments.
- I then started looking at Running Sum in Queries, at this stage I
realised I was out of my
depth. (Which is not very deep at all!)


My questions:
(1) Do I do the calculation in a Query first, then base the Form /
Report on the Query?
(2) How do I do the calculation?

Any help will be appreciated.

Thanks.


Tables
tblPatient
PATID, Autonumber, Key

tblAppointment
APPID, Autonumber, key
PATID, Number
APPDATE, Date



  #3  
Old July 9th, 2009, 09:14 AM posted to microsoft.public.access
Peter Noneley
external usenet poster
 
Posts: 13
Default Where do I Calculate Previous Record?

Thanks Roger and Bruce.

I have used the info, and learnt a great deal !

Your help is much appreciated.
 




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 12:27 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.