Hey everybody.
I have two tables. The first table lists all of the client ids of the clients I am interested in analyzing. The second table lists various data from their different visits to the office.
I want to create a query that will list all of the clients and their visits to the office within the first month of their visit, within the second month, etc.
The tricky part (for me) is that clients start their visits at different times (for example, someone's first visit may be January 3rd, 2004 and someone else might show up for their first visit March 5th, 2005.
For example, if Client X starts his visits on March 15, 2005, I want to list all of his or her visits from March 15, 2005 to April 15, 2005. Likewise, I would like to list all of Client Y's visits from November 1, 2006 to December 1, 2006 (assuming their first visit was November 1).
Hopefully I explained the problem clearly, and that it is feasible This site is great, and thank you to everyone for your time!
-Chris
4 1579 ADezii 8,834
Recognized Expert Expert
Hey everybody.
I have two tables. The first table lists all of the client ids of the clients I am interested in analyzing. The second table lists various data from their different visits to the office.
I want to create a query that will list all of the clients and their visits to the office within the first month of their visit, within the second month, etc.
The tricky part (for me) is that clients start their visits at different times (for example, someone's first visit may be January 3rd, 2004 and someone else might show up for their first visit March 5th, 2005.
For example, if Client X starts his visits on March 15, 2005, I want to list all of his or her visits from March 15, 2005 to April 15, 2005. Likewise, I would like to list all of Client Y's visits from November 1, 2006 to December 1, 2006 (assuming their first visit was November 1).
Hopefully I explained the problem clearly, and that it is feasible This site is great, and thank you to everyone for your time!
-Chris
- Create qryFirstVisit (will contain a listing of Clients and the Date of their 1st visits).
- SELECT tblOfficeVisits.Client, First(tblOfficeVisits.Visit) AS FirstOfVisit
-
FROM tblOfficeVisits
-
GROUP BY tblOfficeVisits.Client;
- Create qryVisitsForFir stMonth. This Query will contain both qryFirstVisit and tblOfficeVisits joined on qryFirstVisit.[Client] ==> tblOfficeVisits .[Client] and will contain all visits from each Client which were less than or equal to 1 Month from their 1st visit:
- SELECT qryFirstVisit.Client, qryFirstVisit.FirstOfVisit, tblOfficeVisits.Visit
-
FROM qryFirstVisit INNER JOIN tblOfficeVisits ON qryFirstVisit.Client=tblOfficeVisits.Client
-
GROUP BY qryFirstVisit.Client, qryFirstVisit.FirstOfVisit, tblOfficeVisits.Visit
-
HAVING tblOfficeVisits.Visit Between [FirstOfVisit] And DateAdd("m",1,[FirstOfVisit]);
Thanks so much for your help. Your code works perfectly to get the clients visits within their first month, now I am stuck on creating queries that will list the visits in their second month, third month, etc.
I tried modifying your last code a bit: - SELECT [qryClinic Visit History Patient First Visit].PatientID, [qryClinic Visit History Patient First Visit].FirstOfVisit, [Clinic Visit History Sorted].VisitDate
-
FROM [qryClinic Visit History Patient First Visit] INNER JOIN [Clinic Visit History Sorted] ON [qryClinic Visit History Patient First Visit].PatientID=[Clinic Visit History Sorted].PatientID
-
GROUP BY [qryClinic Visit History Patient First Visit].PatientID, [qryClinic Visit History Patient First Visit].FirstOfVisit, [Clinic Visit History Sorted].VisitDate
-
HAVING [Clinic Visit History Sorted].VisitDate BETWEEN ([FirstOfVisit] + DateAdd("m",1,[FirstOfVisit])) AND DateAdd("m",2,[FirstOfVisit]);
In particular, I changed this line of your code: - HAVING [Clinic Visit History Sorted].VisitDate BETWEEN [FirstOfVisit] AND DateAdd("m",1,[FirstOfVisit]);
to - HAVING [Clinic Visit History Sorted].VisitDate BETWEEN ([FirstOfVisit] + DateAdd("m",1,[FirstOfVisit])) AND DateAdd("m",2,[FirstOfVisit]);
in an attempt to get the visits dates within the 1st to 2nd month (so if the patients first visit was on January 1st, the query would return the patients visit dates from February 1st to March 1st).
Any ideas?
EDIT: I figured it out. For those who are interested, the code looks like: - HAVING [Clinic Visit History Sorted].VisitDate BETWEEN DateAdd("m",1,[FirstOfVisit]) AND DateAdd("m",2,[FirstOfVisit]);
Now onto a more complex problem to add functionality: Is it possible to create a new query or add to this one that will check to see if there is a 'gap' in client visit dates greater than or equal to 'X' days, and if there is then their next visit after the 'X' day gap is then considered another 'first visit'?
Eg. Client 1's first visit is January 1st, 2006. He/she visits several times in January, February, and March. He or she then doesn't visit again until November 3rd. I would like to list Client 1's visit dates in the 'FirstMonthsVis its' table as the visits from January 1st to February 1st, 2006, AS WELL AS from November 3rd to December 3rd.
If I am unclear, please let me know. Thanks so much in advance!
-Chris
ADezii 8,834
Recognized Expert Expert
Thanks so much for your help. Your code works perfectly to get the clients visits within their first month, now I am stuck on creating queries that will list the visits in their second month, third month, etc.
I tried modifying your last code a bit: - SELECT [qryClinic Visit History Patient First Visit].PatientID, [qryClinic Visit History Patient First Visit].FirstOfVisit, [Clinic Visit History Sorted].VisitDate
-
FROM [qryClinic Visit History Patient First Visit] INNER JOIN [Clinic Visit History Sorted] ON [qryClinic Visit History Patient First Visit].PatientID=[Clinic Visit History Sorted].PatientID
-
GROUP BY [qryClinic Visit History Patient First Visit].PatientID, [qryClinic Visit History Patient First Visit].FirstOfVisit, [Clinic Visit History Sorted].VisitDate
-
HAVING [Clinic Visit History Sorted].VisitDate BETWEEN ([FirstOfVisit] + DateAdd("m",1,[FirstOfVisit])) AND DateAdd("m",2,[FirstOfVisit]);
In particular, I changed this line of your code: - HAVING [Clinic Visit History Sorted].VisitDate BETWEEN [FirstOfVisit] AND DateAdd("m",1,[FirstOfVisit]);
to - HAVING [Clinic Visit History Sorted].VisitDate BETWEEN ([FirstOfVisit] + DateAdd("m",1,[FirstOfVisit])) AND DateAdd("m",2,[FirstOfVisit]);
in an attempt to get the visits dates within the 1st to 2nd month (so if the patients first visit was on January 1st, the query would return the patients visit dates from February 1st to March 1st).
Any ideas?
EDIT: I figured it out. For those who are interested, the code looks like: - HAVING [Clinic Visit History Sorted].VisitDate BETWEEN DateAdd("m",1,[FirstOfVisit]) AND DateAdd("m",2,[FirstOfVisit]);
Now onto a more complex problem to add functionality: Is it possible to create a new query or add to this one that will check to see if there is a 'gap' in client visit dates greater than or equal to 'X' days, and if there is then their next visit after the 'X' day gap is then considered another 'first visit'?
Eg. Client 1's first visit is January 1st, 2006. He/she visits several times in January, February, and March. He or she then doesn't visit again until November 3rd. I would like to list Client 1's visit dates in the 'FirstMonthsVis its' table as the visits from January 1st to February 1st, 2006, AS WELL AS from November 3rd to December 3rd.
If I am unclear, please let me know. Thanks so much in advance!
-Chris
You can create a [Gap] Field in tblOfficeVisits , and calculate the Gap between successive visits by Executing the following code (code only takes into account 1 Client, must factor in for > 1): - Dim MyDB As DAO.Database, MyRS As DAO.Recordset
-
Dim RS_Clone As DAO.Recordset, intGap As Integer
-
-
Set MyDB = CurrentDb()
-
Set MyRS = MyDB.OpenRecordset("tblOfficeVisits", dbOpenDynaset)
-
-
Set RS_Clone = Me.RecordsetClone
-
-
MyRS.MoveFirst
-
RS_Clone.Move 1 'move to 2nd Record
-
-
Do While Not RS_Clone.EOF
-
intGap = DateDiff("d", MyRS![Visit], RS_Clone![Visit])
-
MyRS.MoveNext 'MyRS must be in sync with RS_Clone
-
MyRS.Edit
-
MyRS![Gap] = intGap
-
MyRS.Update
-
MyRS.MovePrevious 'move to Original position
-
MyRS.MoveNext: RS_Clone.MoveNext
-
Loop
-
-
-
RS_Clone.Close
-
MyRS.Close
-
Set RS_Clone = Nothing
-
Set MyRS = Nothing
OUTPUT: -
Client Visit Gap
-
1 1/1/2007
-
1 1/28/2007 27
-
1 2/15/2007 18
-
1 3/12/2007 25
-
1 4/19/2007 38
-
1 6/2/2007 44
-
1 7/14/2007 42
-
1 8/26/2007 43
-
1 9/30/2007 35
-
1 11/23/2007 54
-
1 12/31/2007 38
-
1 1/3/2008 3
I put the code listed above in VB between a Sub DateGap() and EndSub, but when I try to execute the code I get the error:
Compile Error: Invalid use of Me keyword
in reference to this line of code: - Set RS_Clone = Me.RecordsetClone
How should I execute this code to get it to run successfully?
Note: Same error applies if I try placing the code between a Function DateGap() and EndFunction
EDIT: I got it to work now, by changing the line above to: - Set RS_Clone = MyDB.OpenRecordset("tblOfficeVisits", dbOpenDynaset)
(putting this code as a Sub)
Will this change of code have any negative implications? It seems to work fine so far.
I assume the code above at the very beginning of this thread will have to be re-worked to take into account the 'gap' entry. It would have to compare the Gap size, and if it is bigger than X then it would have to count the next visit as another initial visit, but I am not sure how to code that in. Does my reasoning make sense? How would you implement that?
Thanks again,
-Chris
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Guy Hocking |
last post by:
Hi there,
I am having a few problems compiling a list box that is conditional on what
is selected in another list box.
What i need is a List box (lstArea) that displays one thing when the List
Box (lstRegion) is selected East or West. Basically the areas will change
when East or West is selected in lstRegion.
The data comes from an SQL...
|
by: L. D. James |
last post by:
Can someone help me to define a format of a database, or a table that has a
field that will have tables in that field? Please look at the example and
explanation below:
Table: Roster
---------------------------------------------------
|User Name | User ID | Status | Daily Activity Log |...
|
by: jhwagner |
last post by:
I need to use double data entry with an MS Access database. I have
read many arguments and reasons against this on this group but I have
to do this. I have seen various tips on how this can be done including
the use of queries but this hasn't worked satisfactorily. I have two
people who know Access just barely enough to enter the data so...
|
by: source |
last post by:
a function that would: return the 5th element from the end in a singly
linked list of integers, in one pass, and then provide a set of test cases
against that function.
Can we do this in CSharp?
If no, then can anybody tell me how to go about coming with the solution.
How do u develop test cases for any software you write?
Any insight...
|
by: Jimbo |
last post by:
Hi, I'm working on some basic analysis stuff and want to (ultimately)
display my data on a chart by a month breakdown.
To get each months data I need to run a separate query on the db, but I
want to display all the data in a table form, basically with columns
representing the month period.
So Is it possible for me to create a table object...
| |
by: PC Datasheet |
last post by:
An Access user saw my name in a newsgroup and sent me a request for help on
a project. As part of the project, a list of the dates in a month was
needed. For anyone needing a list of dates in a month, here is what I used:
1. Create a table named TblNumbers with one field named Num and populate
the table with 1 to 31
2. Create a query...
|
by: B1ackwater |
last post by:
We've fooled around with Access a bit, but only using the
single-user store-bought version. It seems to be a good
database - versatile and infinitely programmable - and
can apparently be used as a front end to SQL server if
we ever needed to go that route.
But - is there a client/server version of Access ? Looking
on the CDW site there is...
|
by: Paul H |
last post by:
I have a db that stores people and their birth dates. On any given day, I
need to know who has a 40th birthday one month from now. I will only be
running the query on week days but of course some peoples 40th birthdays
will fall on Saturday and Sunday, I may also be out of the office on certain
days. So I need to "cast a net" to catch all...
|
by: rn5a |
last post by:
During registration, users have to provide their date of birth. For
the date & month part, there are 2 dropdown lists & for the year,
there's a textbox. These 3 fields are finally merged together to
populate a MS-Access database table in a column named DOB whose data
type is Date/Time.
There's another page named, say, MyPage.asp, in the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |