473,569 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pronblem Counting occurrences regardless of field

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 which of the 5 fields
it was entered into. Can anyone suggest a remedy for this.

Many Thanks
Glenn
Nov 12 '05 #1
2 3115
I am tempted to say "proper table design", because it is almost certain that
an arrangment as you describe violates relational database design principles
and that is why you are having trouble. If those fields were records in a
related subtable with some identification to distinguish between them, it
would be the proverbial "duck soup" to count them.

Short of that you can create a Query with one calculated field (in this case
to count the times that "5" was entered in any of the fields).

NoWFive:
IIf([Field1]=5,1,0)+IIf([Field2]=5,1,0)+IIf([Field3]=5,1,0)+IIf([Field4]=5,1
,0)+IIf([Field5]=5,1,0)

That will count the occurrences of "5" in each record. Then in Query Design,
on the menu, View | Totals, and change the "Group By" that appears
automatically under "NoWFive" to "Sum". That will sum the counts and give
you the total. Sounds complicated, perhaps, but it won't be.

Take a look at the SQL for the Totals Query:

SELECT
Sum(IIf([Field1]=5,1,0)+IIf([Field2]=5,1,0)+IIf([Field3]=5,1,0)+IIf([Field4]
=5,1,0)+IIf([Field5]=5,1,0)) AS NoWFive
FROM tblFiveSimilarF ields;

If you put that into a variable, with "X" replacing all fives, then it is
easy to write code to replace the "X" with whatever number you want to
count, and execute the Query from code.

But if the fields, with an additional identification field, were kept in a
related table, it would be just one, simple totals query, counting the id
field, WHERE the value equals the number you want to search for.

Larry Linson
Microsoft Access MVP

"Glenn Cornish" <gl***@southwes t.com.au> wrote in message
news:3f******** @usenet.per.par adox.net.au...
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 which of the 5 fields it was entered into. Can anyone suggest a remedy for this.

Many Thanks
Glenn

Nov 12 '05 #2
"Glenn Cornish" <gl***@southwes t.com.au> wrote in message news:<3f******* *@usenet.per.pa radox.net.au>.. .
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 which of the 5 fields
it was entered into. Can anyone suggest a remedy for this.

Many Thanks
Glenn


Less than optimal design.

SELECT fieldA As X
FROM tableA
UNION ALL
SELECT fieldB As X
FROM tableA
....

then do your query on that.
Nov 12 '05 #3

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

Similar topics

1
1871
by: francescomoi | last post by:
Hi. I'm using 'strpos', but wonder whether this function exists: find_string($haystack, $needle) which returns an array with all the numeric positions of the occurrences of needle in the haystack. Thank you very much.
8
3844
by: DrNoose | last post by:
Hi! I'm writing a program that is supposed to read a line of input, count the words and the number of occurrences of each letter. Then it should prints the number of occurrences of each letter that appears in the input line. For example, if I typed "I say Hi." it should give the following output: 3 words 1 a
8
2363
by: Peter Bungart | last post by:
I have a text field in Access (XP) that lists the occurrences of various plants, which are delimited within the field by commas (e.g., cactus, mesquite, yucca, cliffrose). Is there a way to tabulate the occurrence of each type of plant within the field, essentially allowing me to consider the text as data which can be analyzed across a...
5
1812
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 as pass or fails dependent on a batch number.
4
1913
by: Dado | last post by:
I have a next situation with the textbox field: A - B = C 1. How to fill the A fill with the data from my previous recordset ? Can I do it with the expression builder ? 2. I want that every field I can edit or count, depends on what fileds I input the value ?
11
10064
by: b_or_not2c | last post by:
Hi, I am trying to count the number of substrings within a string. I am fairly new to programming and need a headstart. Any info would be appreciated. Thanks, A
3
2059
by: newstips6706 | last post by:
The Art of Counting TIME -------------------------------------------------------------------------------- As the research done on the paper titled: "The Number '1'", which yielded the following results: WHAT passes through this PERFECT MIRROR, PI , that reflects off , PI to give "a mirror image of " PI known as: "The Number '1'?
1
1521
by: BillH | last post by:
As new Records are added I need to in a Query, count the number of occurrences of several specific Fields that have change from the previous record. As a reference point, each Record is unique for Date and Time so if the next Record is added to the DB, I want to know if Field 'x' has changed in value from the entry in the previous Record. ...
25
3900
by: Rick Collard | last post by:
Using DAO 3.6 on an Access 2002 database, I'm getting unexpected results with the FindFirst method. Here's the simple code to test: Public Sub FindIt() Dim db As Database, rs As Recordset Dim sCriteria As String Set db = DBEngine.Workspaces(0).Databases(0) Set rs = db.OpenRecordset("tblTest", dbOpenDynaset)
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
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. ...
1
7672
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...
0
6283
agi2029
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...
1
5512
isladogs
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...
0
5219
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...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
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
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.