Forms :: Count Distinct Values In A Control?
Nov 22, 2014I would like to count distinct values on a control in the footer of a search form. How to accomplish it.
View RepliesI would like to count distinct values on a control in the footer of a search form. How to accomplish it.
View RepliesI am a novice and have been searching to no avail for a solution to my problem. I have a main form and a subform (datasheet view) of a table. In my main form I have various calculations which calculates the data from the subform (when auto-filtered). What I am trying to do is count the distinct [Call Number] reflecting the data from the subform into a textbox in the main form (when subform is auto-filtered).
View 14 Replies View RelatedI am currently trying to make a form which will generate a report for the users. Currently the form has 3 combo boxes where users select which fields they want displayed from the table in the report. They also have sorting options next to them (Asc or Desc). I am now trying to put in a multi select list box under each combo box to allow users to filter the report to their liking. Currently I am trying to pull distinct values from the specific field of the table and display them in the listbox for users to select.
I have tried using vba to set me.filter1.rowsource = SELECT DISTINCT me.combo1 FROM EVAP_Database, but this doesnt seem to work. I have also tried a few other codes and still no luck.
Table: EVAP Database
Combo: Combo1
Filter Listbox: Filter1
Hi Everyone!,
I have a table with the follwing;
ShopID, CustomerID, Month, Item_ref, Product Category
There are about one thousand shops.
The CustomerID field is only unique per shop.
I.e. all transactions for customer ID '002' in shop 1 will be for the same customer, but customer ID '002' could appear in another shop and will be a different customer,
I want to be able to bring back a list of distinct customers, the number of items they have had and the product categories.
Has anyone got any ideas how I do this? I presume I would need to do a count distinct or something??
thanks!,
Sasha
I have a table like this in MS Access database:
IDDateCustomerIDInvoiceNoItemNoAmount
101/01/2007A1AAA1
201/01/2007A1BBB2
301/01/2007A2CCC3
601/01/2007B5AAA6
701/01/2007A6BBB7
801/01/2007B5BBB8
I want to get disctinct count of InvoiceNo while summing up Amount by Date and CustomerID in one query. Firstly, I tried to use correlated query to count unique records but it failed.
SELECT A.Date, A.CustomerID, (SELECT COUNT(B.InvoiceNo) FROM Table1 B WHERE B.Date = A.Date AND B.CustomerID = A.CustomerID ) AS CountOfDistInvNo, Sum(A.Amount) AS SumOfAmount
FROM Table1 A
GROUP BY A.Date, A.CustomerID;
The result of Count is not a unique count. Can anyone tell me what's wrong with this correlated query? :confused:
After hours of googling on internet, the solution I got is equivalent to querying on top of the resulting table from another query.
My final query is
SELECT B.Date, B.CustomerID, Count(B.InvoiceNo) AS CountOfInvoiceNo, Sum(B.SumOfAmount) AS SumOfAmount
FROM (SELECT A.Date, A.CustomerID, A.InvoiceNo, SUM(A.Amount) AS SumOfAmount FROM Table1 A GROUP BY A.Date, A.CustomerID, A.InvoiceNo) AS B
GROUP BY B.Date, B.CustomerID;
Is there a better solution than this in Access? :)
Thanks,
Huyeote
Tried several suggestions in the forum but haven't found one to match my needs.
I have one table, Jupiter and need to use this query
SELECT Jupiter.codename AS Build, Count(Jupiter.tooling_ind) AS [# Needing Tool], Count(IIf([tool_req_type]='OR',([requisition_no]))) AS [# Tooled], [# Tooled]/[# Needing Tool] AS [% Tooled], Jupiter.tooling_ind
FROM Jupiter
GROUP BY Jupiter.codename, Jupiter.tooling_ind
HAVING (((Jupiter.tooling_ind)="Y"));
For each "codename", there is an attached "part_no" which can appear under a codename several times. The problem is that I need to count only one instance of the "part_no" for each "codename".
So, my query looks like this:
Build # Needing Tool #Tooled
LP1 769 192
The # Needing Tool is counting every record that, say pn 10592 shows up in and I need it to be counted only once in each "Build"
I did try this suggestion I found with no results.
SELECT Jupiter.codename AS Build, Count(Jupiter.tooling_ind) AS [# Needing Tool], Count(IIf([tool_req_type]='OR',([requisition_no]))) AS [# Tooled], [# Tooled]/[# Needing Tool] AS [% Tooled], Jupiter.tooling_ind
FROM (SELECT DISTINCT Jupiter.part_no FROM Jupiter)Jupiter
GROUP BY Jupiter.codename, Jupiter.tooling_ind
HAVING (((Jupiter.tooling_ind)="Y"));
Is there a way to do this somehow?
Thanks!
Toni
I've searched on google for count distinct help but I had no luck. I'm counting 2 different columns and when the query is run the counts in both columns appear exactly the same. Also, I need a SUM distinct (if possible) to sum only where it is being counted in 'CountOfCar_Nr'. Here is my SQL....
View 3 Replies View RelatedI'm building a sort of uberquery to do some calculations on a dataset for me, and I reached a point where I'm having some problems. I'm going to have to assemble the main query by doing a join on several subqueries.
Essentially, I have one table with the following fields (DrawingNo, DrawingRev) and another table with a great deal of data in it, but as far as this problem is concerned, it has (DrawingNo, DrawingRev, OrderNo, SPOOL). I have several tests that have to be performed.
The first table contains a master listing of al drawings we are supposed to have, the second contains information related to procesing the drawings. There is one row in the second table for each piece to be made from each drawing.
The first test is to verify that no gievn revision of any drawing has been split across more than one OrderNo. Essentially, I Count(OrderNo) and group by DrawingNo and DrawingRev, so that there is one line in the query for each drawing/revision pair, and a count of the number of OrderNos that meet those criteria.
The second test (and this is the one I have a problem with) involves taking a count of the number of unique values of DrawingRev that occur for a given DrawingNo. Something like SELECT Count(DISTINCT Drawingrev) FROM SecondTable GROUP BY DrawingNo should work, but Access doesn't appear to support "Count(Distinct". How do I get around this, and remember that any answer has to be able to be used as a subquery.
Hello all,
I am new to this forum. I have this problem where I need to sort the 4 books in the tables below according to the highest quantity of book sold.In this scenario,
Book C would be 1st in the table with a total quantity of 8.
How do I write a query in access to perform such operation. I have to use DISTINCT to get each book and also count the quantity(e.g. Book C:5+8).
But it seems that I can't use Count and distinct together in Access.
Title SalesNo Quantity
BookA22
BookB 31
BookC 45
BookC 53
BookD 6 1
Hope u all can help!
I have a query I have 4 fields:
E.G.
Field1 Field2 Field3 Field4
C 20 25 145541
C 40 20 145541
C 10 10 145540
D 20 20 145540
D 10 10 145538
I need to obtain:
C 70 55 2
D 30 30 2
I need to group Field1 and sum Field 3 and field3 and count the UNIQUE ID in field 4.
Hello, guys. First of all, may all of you have a very cool New Year 2007!
In my MS Access database i have 2 tables: Table1 and Table2. These are related by means of the fields Field1 (Primary key of Table1) and Field2 (Secondary key of Table2). The relation is 1 to Many.
I pretend to count the rows from the Table2 with different Field2 values. Thus, the following query would be an ideal solution:
SELECT COUNT(DISTINCT Field2)
FROM Table2
Unfortunately, the DISTINCT clause is not admitted within COUNT parenthesis. So, what i came up with is:
SELECT COUNT(*)
FROM Table1
WHERE Field1 IN (SELECT DISTINCT Field2 FROM Table2)
It works, but it takes too long to run the main query, where i embedded several subqueries like the one above.
Is there any other way to get the same result reducing the response time?
Thanks for your attention in advance.
Extended Cost] and salestran.[Extended Price] for each salestran.[SKU Code/Number], Count the number of unique customers, salestran.[Customer Code/Number], per SKU for any transactions equal to or after salestran.[Transaction Date] 11/1/2014.
Problem is, doing a regular count on the Customer field returns an incorrect value. It counts the number of times the sku appears within the given date range, ie 6 transactions with 2 customers, my count says 6. I need a distinct count on the customer, for the above example I want to see 2. Here is the code I have so far which yields an error of "At most one record can be returned.." distinct count in my Select statement along with the other fields I want to see, ie Summary data and SKU.
SELECT Salestran.[SKU Code/Number], (SELECT COUNT(cd.[Customer Code/Number]) AS Count FROM (SELECT Distinct [SKU Code/Number], [Customer Code/Number] FROM Salestran) as cd GROUP BY cd.[SKU Code/Number]) AS [Number of Customers]
FROM Salestran
WHERE (((Salestran.[Transaction Date])>=#11/1/2014#))
GROUP BY Salestran.[SKU Code/Number];
I have a table with the following values.
EMPLLOYEE_ID
JOB
PAY_DATE
LOCATION
Most employees have 10 to 15 rows. I only want to pull ALL rows for employees ONLY if there is a distinct count from DATE_PAID greater than 1. There are cases where an employee might have two pay checks generarted for the same PAY_DATE.
I have a query that contains Invoices(usually 2 line items per invoice) Taxable and NonTaxable. I need to able to basically export it to excel on multiple worksheets when the Amount of unique invoice number reaches 15.
From all my scouring on the internet I can't find anything with this criteria.
I have the following SQL which returns rows of distinct numbers that are calculated from a field.
SELECT Distinct (Left([ProjectID],4)) AS NumberOfCalls
FROM tblProject;
ProjectID looks something like this : 1307-IND-001 and NumberOfCalls looks like : 1307
I need to count the number of unique "NumberOfCalls" entries that there are in a list of about 50 rows. Currently the SQL returns a list of numbers like this:
1307
1311
1401
etc...
I just want NumberOfCalls to show "3". Is there an easy way to do this?
I'm trying to write a query to get a count of Volunteers under a certain Job Code for a given year - problem comes in that a single Volunteer may record hours multiple times under a Job Code in a given Fiscal Year. I can't seem to get "Unique Values" to work. From my research it looks like I need a two-part query but (as a newbie) I'm not quite sure how to write that. I have two queries, one that works and one that doesn't.
This one counts total amount of hours volunteered under a given Job Code, it works:
Code:
SELECT tblHoursWorked.FiscalYear, tblHoursWorked.JobCodeLookup, Sum(tblHoursWorked.HoursWorked) AS [Sum Of HoursWorked]
FROM tblHoursWorked
GROUP BY tblHoursWorked.FiscalYear, tblHoursWorked.JobCodeLookup;
HAVING (((tblHoursWorked.FiscalYear)=[Enter Year:]));
This one attempts to count number of Volunteers that worked under each Job Code in a given year - it instead counts number of entries under that job code. What I think I need to do is count unique instances of the NamesIDFK, but I can't seem to get that to work.
Code:
SELECT DISTINCT tblHoursWorked.[JobCodeLookup]
FROM tblHoursWorked
GROUP BY tblHoursWorked.[JobCodeLookup];
1) correcting my second query and 2) putting them into one query so I can use them in a report.
SELECT qryHoursReq.VolunteerId, qryHoursReq.Name, qryHoursReq.Program, Sum(qryHoursReq.Total_Time) AS SumOfTotal_Time, qryHoursReq.S_date
FROM qryHoursReq
GROUP BY qryHoursReq.VolunteerId, qryHoursReq.Name, qryHoursReq.Program, qryHoursReq.S_date
HAVING (((qryHoursReq.S_date) Between [startdate] And [enddate]));
This is my query
I'm trying to get a count of distinct volunteerID in an unbound textbox on report.
If I use =Count(*) I get 2 when I put in date parameters and it groups by program
This is kind of correct, but, these 2 are the same person, she had different days she participated.
What code can I use for only get a count of 1
FOrgot to mention, when I use the DCount with numerous examples, I get #Error
I have 2 tables linked with a 1 to many relationship by NAME. Tables look like this....
TBL-STORE
NAME ADDRESS
Walmart 12 Nowhere
Target 14 Somewhere
Lowes 10 Anywhere
Sears 16 Nowhere
TBL-PURCHASES
NAME [NUMBER OF ITEMS] [PURCHASE DATE]
Walmart 4 1/4/14
Walmart 2 1/5/14
Target 0 1/5/14
Lowes 3 1/5/14
Sears 1 1/5/14
Sears -1 (returned to store) 1/6/14
I want a DISTINCT COUNT of [NAME] if Total[NUMBER OF ITEMS]>0, so the correct number will be 2 in the example.
This is one way I've tried to write the SQL, but I keep getting an error...
SELECT Count([TBL-STORE].[NAME])
FROM [TBL-STORE] INNER JOIN [TBL-PURCHASES] ON [TBL-STORE].[NAME] = [TBL-PURCHASES].[NAME]
WHERE ([TBL-PURCHASES].[NUMBER OF ITEMS]>1)
HAVING ([TBL-STORE].[NAME])="DISTINCT");
I also tried an Count(IiF( and can't get that to work either..
In Access 2013 I have 2 tables
tbAssembleias
tbEntities
The tbEntities, have a fiel called tbPresent (yes/no) to register the presents in a condominium meeting.
Table Name: tbEntities
Fields:
tbEntId...tbPresent (yes / no)..........tbVotes 1.........ye...........................5
2.........no...........................3
3.........yes..........................4
4.........no...........................6
In the form is the table tbAssembleias, but I want to put from the other table which is not present in the form:
1. a control that count how many are present (= yes)Ex: Appearances 22. a control that sum the votes of those presentEx: Votes 9I already have a query that count how many are in the meeting, but cant realize how to pass the information to the field in the form..This is the SQL view of the query with the real field names - and working:
SELECT Count(tbEntidades.tbAssPresente) AS ContaPresentes, tbEntidades.tbAssPresente
FROM tbEntidades
GROUP BY tbEntidades.tbAssPresente
HAVING (((Count(tbEntidades.tbAssPresente))=True) AND ((tbEntidades.tbAssPresente)=True));
I am trying to get a count of the unique customers in an access 2010 database
After some research it seems i should be using
SELECT Count(Distinct [Customer]) FROM [tblMain];
But when i use this i get
Syntax error (missing operator) in query expression 'Count(Distinct Customer)'.
I have tried leaving out the square brackets but this does not work....
I have a form and subform. I need to -
1) show the number of records in the subform on the main form
2) count the number of records in the subform where a value [Public] is True
3) count the number of records in the subform where another value [Analyst] is True.
I can achieve the first two by using the following VBA on the Main form current event -
Quote:
Private Sub Form_Current()
Dim rst As DAO.Recordset
Dim lngCount As Long
[Code]....
when i try to get number 3 done I get the same value as for [Public] (using lngCount for both...not surprising really!)
how i can get a count done for [Analyst] = True in the same event?
Hi all,
I had table with following data
Table
f1 f2 f3
1 10 AB
1 11 WW
2 10 DD
2 11 DD
f3 is memo field
I had to retrieve data by grouping records based on f1 value
and i had to display f3 value as "-" if all f3 values for a f1 are distinct.
If all f3 values contains the same value then i should display that value.
I should get output like this
f1 f3
1 -
2 DD
I tried a lot by taking the distinct count of the records and displaying - when count is > 1
but i am not able to succeed.
please any one give the solution.
waiting for your help.
Thanks
I have a combo box that I want to display titles of discussion that fall within a date range. I set up the query as such;
SELECT DISTINCT Discussions.Discussion_Title, Discussions.Discussion_Date
FROM Discussions
WHERE (((Discussions.Discussion_Date) Between ([forms]![DiscussionsForm2]![txtStartDate]) And ([forms]![DiscussionsForm2]![txtEndDate])))
ORDER BY Discussions.Discussion_Title;
It works but not quite the way I want it too. I would like the combobox to display only unique titles but right now it shows the same title if it was used on another date. I guess its showing distinct titles and dates, while I want it to display just distinct titles.
I have an option group which should display a value from a table if txtWords is null, but the result of a query if txtWords is not null. But though it shows the right results when I load the form, updating txtWords gives me all sorts of errors.
txtWords is in the main form, while the option group optLengthCat is in a subform (but inline).
Form_OnCurrent() event:
Code:
'Enable or disable the option group
If Len(Me.txtWords.Value & vbNullString) = 0 Then
Me.fsubLengthCat.Form!optLengthCat.Enabled = True
Else
Me.fsubLengthCat.Form!optLengthCat.Enabled = False
[Code] .....
When I put this into txtWords_AfterUpdate() it starts throwing up errors. Specifically, when I delete a subform record using SQL I get 'record was already deleted by another user'; I think I might have fixed the problem with Me.Requery, but it feels really inefficient.
Should I be using an unbound control? If yes, how do I make an unbound control that can edit or add new records?
I am trying to improve a work process using an existing Access DB.We have a form with multiple texts boxes on it. I need to search through these boxes to determine the total number of occurrences of a specific value. This is not tied to a table.
The text boxes I'd be searching through all have related names: "Element0" to "Element40". And I'd most likely be looking for a "/" within the value in the boxes (value could be 12345/01, for example).Would then be using the result in VBA to apply some conditions, so I would prefer if I could do the count in VBA (the count/sum is the part that is hanging me up.)
I've found multiple ways to accomplish this from a table, but nothing for what I have to work with.I am unclear in my description of what I am trying to do, let me know and I will try to provide more information.
Below is a sample of the table with the data. I manually added the 1 and 0 to the hc_Year field. However, I would like to create an Update query that will add a 1 to the hc_Year if its the first instance of PIDM & regsYear and add a 0 to the records that are not the first instance.
PIDM | regsYear | hc_Year
52 | 2009 | 1
52 | 2010 | 1
201 | 2007 | 1
201 | 2007 | 0
201 | 2007 | 0
201 | 2008 | 1