473,322 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Counting the number of different records in a table or query

3
Hey all,

I've been struggling with this problem for a few days now. The table looks like this

T_PROJECT_FILES
fields: projectId, unitId
Now, I want to count the number of records with different values in unitId, but with a specific value (e.g. 1) in projectId. The value of 'projectId' is coming from another form using e.g.

Expand|Select|Wrap|Line Numbers
  1.  Forms!F_Start.lblActiveProjectId.caption 
The number is finally going to be printed on a label.

I have previously tried to make a query like this (I called it Q_PROJECT_FILES_UNITCOUNT):

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT T_PROJECT_FILES.unitId, T_PROJECT_FILES.projectId
  3. FROM T_PROJECT_FILES
  4. GROUP BY T_PROJECT_FILES.unitId, T_PROJECT_FILES.projectId
  5. HAVING (((T_PROJECT_FILES.projectId)=[Forms]![F_Start]![lblActiveProjectId].[caption]));  
and then access the query using querydef:
Expand|Select|Wrap|Line Numbers
  1.     Dim db As Database
  2.     Dim rs As DAO.Recordset
  3.     Dim qdf As QueryDef
  4.  
  5.         Set db = CurrentDb
  6.         Set qdf = db.QueryDefs("Q_PROJECT_FILES_UNITCOUNT")
  7.         Set rs = qdf.OpenRecordset()
  8.  
but this returned a run-time error '3061': "There is too few parameters. Expected 1"

Any suggestions?
Jan 18 '08 #1
3 1863
Megalog
378 Expert 256MB
T_PROJECT_FILES
fields: projectId, unitId
Now, I want to count the number of records with different values in unitId, but with a specific value (e.g. 1) in projectId. The value of 'projectId' is coming from another form using e.g.

Expand|Select|Wrap|Line Numbers
  1.  Forms!F_Start.lblActiveProjectId.caption 
Dcount should work well for you here. DCount(Expr, Domain, Criteria)
So in your example, this would return the number of records that have that specific projectId.

Expand|Select|Wrap|Line Numbers
  1. DCount("unitld","T_PROJECT_FILES", "[projectId] = '" & Forms!F_Start.lblActiveProjectId.caption & "'")
Jan 18 '08 #2
JacobZ
3
Dcount should work well for you here. DCount(Expr, Domain, Criteria)
So in your example, this would return the number of records that have that specific projectId.

Expand|Select|Wrap|Line Numbers
  1. DCount("unitld","T_PROJECT_FILES", "[projectId] = '" & Forms!F_Start.lblActiveProjectId.caption & "'")
No - this will only return the number of all records where projectId matches the criteria. Let me clarify with an example of some records:

T_PROJECT_FILES
projectId, unitId
2, 1
2, 2
2, 2
2, 2

Here, if lblActiveProjectId.Caption = 2 your code would return the number '4' - i.e. the total amount of units in project 2. The problem is that I need to calculate how many different units are bound to project 2. In this case it would be 2 (unit 1 and unit 2)

I hope you understand.
Jan 18 '08 #3
JacobZ
3
Are there no solutions to this problem?
Jan 25 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Glenn Cornish | last post by:
I have 5 fields in a table into which numbers between 1 and 45 can be entered. What I am having trouble with is being able to find out is how many times a particular number appears, regardless of...
3
by: Megan | last post by:
hi everybody- i'm having a counting problem i hope you guys and gals could give me some help with. i have a query that retrieves a bevy of information from several different tables. first let...
5
by: chrisc | last post by:
Hello, Hope this is the right place for this... I am creating a testing database for components as they come off a production line. My reports need to select faults that are found, as well...
5
by: ChadDiesel | last post by:
Hello Again, I want to assign a number to each record that will be part of a shipping number. I want the number value to count up until the contract number changes. Then, I want the number to...
18
by: ChadDiesel | last post by:
I appreciate the help on this group. I know I've posted a lot here the last couple of weeks, but I was thrown into a database project at my work with very little Access experience. No other...
2
by: mattytee123 | last post by:
I have about 20 tables, of which I would like to do a union query and count of how many of each different code there is? The simplified verson of the table is structured like this. Code ...
8
by: King | last post by:
Hi I have following MS Acess query Here is the query ID Name Prgm ID Client ID Date Start Time End Time Minutes C4 Trisha TIP DEK0703 7 /7 /2006...
8
by: johnds | last post by:
This is my third question about eliminating accounting entries in a clinical database, yet retaining the valid record. Latest wrinkle is being able to sum the visits to the doctor, and the units of...
8
by: crassostrea | last post by:
Hello and Happy New Year, I have two tables in Access 2003 (Windows XP) with similar, but different, information. We’ll call them table A and table B. I want to count the number of records in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.