Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 1st, 2007, 09:24 AM
Registered User
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Complex(?) Count Query Causing Access to Crash

Hey everybody! This is my first post here, so hopefully I will be able to make it as clear as possible. I have a very large database (over 1,000,000 entries) and my current goal is to find out the number of 'sessions' that a person does during his or her lifetime in the database.

I have a table that has records of each person (each have their own unique ID), and the date of that person's visit. I have defined a session as being complete if the person does not come back for a visit in a 3 week period. After the 3 week period, if the person comes back for another visit, a new session is started.

There are thousands of unique persons in the database, and a person will often visit many many times.

My Goal: to determine how many 'sessions' each patient does.

Someone from another site has suggested using this code:

SELECT x.[Patient ID], Count(x.Date) AS CountOfSessions
FROM Query1 AS x
WHERE (((DateDiff("d",Nz((SELECT TOP 1 Date FROM Query1 WHERE [Patient ID] = x.[Patient ID] AND Date < x.Date ORDER BY Date DESC;),0),[Date]))>21))
GROUP BY x.[Patient ID];
but that Causes Access to crash (I enter it in the SQL code view of a query.

I am using Access 2003 on Windows XP if that helps.

Thank you so much for your time!


Old August 6th, 2007, 11:16 AM
Friend of Wrox
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts

What is Query1? Do you have the SQL from that query? This query relies a lot on that and so the problem may be with Query1, and not with this query.

I would also suggest moving the WHERE clause to another query.

Can you post the SQL from query1?


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cr8 & Stored procedure ..Crash ..Crash swissaKM Crystal Reports 0 January 2nd, 2005 06:02 AM
Can't find record, causes Access to crash mmcdonal Access 2 December 3rd, 2004 02:51 PM
query too complex [email protected] Access 3 August 28th, 2003 09:01 AM
Refresh causing Query Engine Error Deecay Crystal Reports 0 July 10th, 2003 09:27 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.