472,781 Members | 1,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,781 software developers and data experts.

Getting Number of Unique Records

I need some help getting unique records from our database! I work for
a small non-profit homeless shelter. We keep track of guest
information as well as what services we have offered for statistical
purposes.

I've been using

Here's the situation:

I have two main tables:
Guest (stores data such as GuestID, First Name, Last Name, etc.) and
Services (stores data such as the type of service the guest used
(Shelter Bed, Lunch, Dinner, Hygiene Items, etc.), the date the
service was used, and an "alias" connector to the GuestID called
ServicesLink.)

Each month, we track how many Shelter beds we used overall and also
how many UNIQUE guests (ServicesLink) we offered beds to.

I've had success using DCount() with the overall numbers, but this of
course doesn't work with unique records.
I've been toying with Allen Browne's ECount(), which adds another
criteria to DCount() to identify distinct records.

This nearly does what I need it to do, EXCEPT that I can't get it to
let me filter for the ServiceDate without manually entering the dates
in my expression. I want to be able to use a form to enter the date
range and run the query based on that date range.

For instance, in a totals query, I have My ECount expression, and
ServicesType (Group By) as columns.

If I type the date in my Ecount expression manually, such as:
Ecount("ServicesLink","Services","ServiceDate Between #07/01/2007# and
#07/31/2007# and ServiceType=""" &ServiceType&"""","True")
I get the data as the correct unique counts in the first column,
grouped by ServicesType in the second. This is basically what I need.

Ecount Expression w/
manually entered
date range
(Correct) ServicesType
14 Program Dorm
2 Food Basket
7 Temporary ID
84 Personal Needs
99 Men's Dorm

Entering this into a field in a report where I specify the data AND
the service type manually works as well.

HOWEVER, I need to do reports with these unique totals every month and
I want it to be user-friendly to anyone else who needs to pull these
stats. So, I'd like to be able to print a report or run a query,
filtered by date, that includes these fields sorted by a form or field
that allows a user to enter a date range that the query will use to
give me the unique numbers for the date range specified.

I tried to do this with a form "Statistics Information" where the user
can enter a date range with [txtStartDate] and [txtEndDate] and then
click a command button to run the query/report. I tried to enter the
code in my query expression as:

Ecount("ServicesLink","Services","ServiceDate "Between #" & [Form]!
[Statistics Information]![txtStartDate] & "# and #" & [Form]!
[Statistics Information]![txtEndDate] & "#" and ServiceType="""
&ServiceType&"""","True")

I still get the ServiceType in my second column, but in my expression
column, instead of distinct numbers for each of the different types, I
get the same number for all of the rows, which I am assuming is the
distinct number of records for ALL the service types combined.

Ecount Expression w/
Form parameters
date range
(Incorrect) ServicesType
489 Program Dorm
489 Food Basket
489 PN Family Pack
489 Temporary ID
489 Personal Needs
489 Men's Dorm

I've tried doing another query that filters records by a date range
and then trying to do the Ecount (without the date criteria) off that
query, but then I keep getting "Expected 2 Parameters" as an error
message.

At a loss...

Nov 2 '07 #1
2 4369
I haven't used Allen Brown's function, so I don't know. But I can tell you
that your quote marks are off in what you posted. Maybe that was a typo when
you posted. Here's what you posted:

Ecount("ServicesLink","Services","ServiceDate "Between #" & [Form]!
[Statistics Information]![txtStartDate] & "# and #" & [Form]!
[Statistics Information]![txtEndDate] & "#" and ServiceType="""
&ServiceType&"""","True")

That should be:

Ecount("ServicesLink","Services","ServiceDate Between #" & [Form]!
[Statistics Information]![txtStartDate] & "# and #" & [Form]!
[Statistics Information]![txtEndDate] & "# and ServiceType="""
&ServiceType&"""","True")

Notice that two quote marks were removed.

<sr*********@gmail.comwrote in message
news:11**********************@o3g2000hsb.googlegro ups.com...
>I need some help getting unique records from our database! I work for
a small non-profit homeless shelter. We keep track of guest
information as well as what services we have offered for statistical
purposes.

I've been using

Here's the situation:

I have two main tables:
Guest (stores data such as GuestID, First Name, Last Name, etc.) and
Services (stores data such as the type of service the guest used
(Shelter Bed, Lunch, Dinner, Hygiene Items, etc.), the date the
service was used, and an "alias" connector to the GuestID called
ServicesLink.)

Each month, we track how many Shelter beds we used overall and also
how many UNIQUE guests (ServicesLink) we offered beds to.

I've had success using DCount() with the overall numbers, but this of
course doesn't work with unique records.
I've been toying with Allen Browne's ECount(), which adds another
criteria to DCount() to identify distinct records.

This nearly does what I need it to do, EXCEPT that I can't get it to
let me filter for the ServiceDate without manually entering the dates
in my expression. I want to be able to use a form to enter the date
range and run the query based on that date range.

For instance, in a totals query, I have My ECount expression, and
ServicesType (Group By) as columns.

If I type the date in my Ecount expression manually, such as:
Ecount("ServicesLink","Services","ServiceDate Between #07/01/2007# and
#07/31/2007# and ServiceType=""" &ServiceType&"""","True")
I get the data as the correct unique counts in the first column,
grouped by ServicesType in the second. This is basically what I need.

Ecount Expression w/
manually entered
date range
(Correct) ServicesType
14 Program Dorm
2 Food Basket
7 Temporary ID
84 Personal Needs
99 Men's Dorm

Entering this into a field in a report where I specify the data AND
the service type manually works as well.

HOWEVER, I need to do reports with these unique totals every month and
I want it to be user-friendly to anyone else who needs to pull these
stats. So, I'd like to be able to print a report or run a query,
filtered by date, that includes these fields sorted by a form or field
that allows a user to enter a date range that the query will use to
give me the unique numbers for the date range specified.

I tried to do this with a form "Statistics Information" where the user
can enter a date range with [txtStartDate] and [txtEndDate] and then
click a command button to run the query/report. I tried to enter the
code in my query expression as:

Ecount("ServicesLink","Services","ServiceDate "Between #" & [Form]!
[Statistics Information]![txtStartDate] & "# and #" & [Form]!
[Statistics Information]![txtEndDate] & "#" and ServiceType="""
&ServiceType&"""","True")

I still get the ServiceType in my second column, but in my expression
column, instead of distinct numbers for each of the different types, I
get the same number for all of the rows, which I am assuming is the
distinct number of records for ALL the service types combined.

Ecount Expression w/
Form parameters
date range
(Incorrect) ServicesType
489 Program Dorm
489 Food Basket
489 PN Family Pack
489 Temporary ID
489 Personal Needs
489 Men's Dorm

I've tried doing another query that filters records by a date range
and then trying to do the Ecount (without the date criteria) off that
query, but then I keep getting "Expected 2 Parameters" as an error
message.

At a loss...

Nov 3 '07 #2
sr*********@gmail.com wrote:
I need some help getting unique records from our database! I work for
a small non-profit homeless shelter. We keep track of guest
information as well as what services we have offered for statistical
purposes.

I've been using

Here's the situation:

I have two main tables:
Guest (stores data such as GuestID, First Name, Last Name, etc.) and
Services (stores data such as the type of service the guest used
(Shelter Bed, Lunch, Dinner, Hygiene Items, etc.), the date the
service was used, and an "alias" connector to the GuestID called
ServicesLink.)

Each month, we track how many Shelter beds we used overall and also
how many UNIQUE guests (ServicesLink) we offered beds to.

I've had success using DCount() with the overall numbers, but this of
course doesn't work with unique records.
I've been toying with Allen Browne's ECount(), which adds another
criteria to DCount() to identify distinct records.

This nearly does what I need it to do, EXCEPT that I can't get it to
let me filter for the ServiceDate without manually entering the dates
in my expression. I want to be able to use a form to enter the date
range and run the query based on that date range.

For instance, in a totals query, I have My ECount expression, and
ServicesType (Group By) as columns.

If I type the date in my Ecount expression manually, such as:
Ecount("ServicesLink","Services","ServiceDate Between #07/01/2007# and
#07/31/2007# and ServiceType=""" &ServiceType&"""","True")
I get the data as the correct unique counts in the first column,
grouped by ServicesType in the second. This is basically what I need.

Ecount Expression w/
manually entered
date range
(Correct) ServicesType
14 Program Dorm
2 Food Basket
7 Temporary ID
84 Personal Needs
99 Men's Dorm

Entering this into a field in a report where I specify the data AND
the service type manually works as well.

HOWEVER, I need to do reports with these unique totals every month and
I want it to be user-friendly to anyone else who needs to pull these
stats. So, I'd like to be able to print a report or run a query,
filtered by date, that includes these fields sorted by a form or field
that allows a user to enter a date range that the query will use to
give me the unique numbers for the date range specified.

I tried to do this with a form "Statistics Information" where the user
can enter a date range with [txtStartDate] and [txtEndDate] and then
click a command button to run the query/report. I tried to enter the
code in my query expression as:

Ecount("ServicesLink","Services","ServiceDate "Between #" & [Form]!
[Statistics Information]![txtStartDate] & "# and #" & [Form]!
[Statistics Information]![txtEndDate] & "#" and ServiceType="""
&ServiceType&"""","True")

I still get the ServiceType in my second column, but in my expression
column, instead of distinct numbers for each of the different types, I
get the same number for all of the rows, which I am assuming is the
distinct number of records for ALL the service types combined.

Ecount Expression w/
Form parameters
date range
(Incorrect) ServicesType
489 Program Dorm
489 Food Basket
489 PN Family Pack
489 Temporary ID
489 Personal Needs
489 Men's Dorm

I've tried doing another query that filters records by a date range
and then trying to do the Ecount (without the date criteria) off that
query, but then I keep getting "Expected 2 Parameters" as an error
message.

At a loss...
Perhaps an easier way to approach this is to break it into two queries.

The first query would be a totals query something like this (parentheses
indicate the total type):

ServicesLink (Group By)
ServiceType (Group By)
ServiceDate (Where) with Criteria something like Between
[Form]![Statistics Information]![txtStartDate] and [Form]![Statistics
Information]![txtEndDate]

This query would yield all the distinct combinations of people and
services in the time period entered on your form.

The second query would work off the first query and would be a totals
query something like this:

ServicesLink (Count)
ServiceType (Group By)

This query would do the totaling.

Hope this helps,

Carlos

--
Posted via a free Usenet account from http://www.teranews.com

Nov 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bryan Zash | last post by:
When querying a bit field, I am encountering a problem with MS SQL Server returning a larger number of records for a table than the actual number of records that exist within that table. For...
3
by: John Ortt | last post by:
> I have a table of dates in ascending order but with varying intervals. I > would like to create a query to pull out the date (in field 1) and then pull > the date from the subsequent record...
16
by: John Baker | last post by:
Hi: I know this is a strange question, but I have inherited a system where files are copied and records re auto numbered (as an index field) )frequently, and I am wondering how high the number...
1
by: Crimsonwingz | last post by:
I am setting up a database to track incoming shipments by Lot. In one shipment (lot) there will be several items that need to be associated to that lot, but need a unique number to reship by. ...
1
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the...
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
4
by: Sean Shanny | last post by:
To all, Running into an out of memory error on our data warehouse server. This occurs only with our data from the 'September' section of a large fact table. The exact same query running over...
12
by: Lennart Anderson | last post by:
I'm having a MySQl table wih a lot of information. I want to present some main fields in a table on one page. Each record do, of course, have a unique ID. The presnted table will have one field as...
12
by: magmike | last post by:
Accidentally deleted a record. Anyway to get it back? If not, I know the ID number - which is an autonumber field. Because of the related data from other tables, would I be able to create a new...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.