473,609 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Count number of times data is same in two different fields, same table

10 New Member
Hello im trying to figure out a sql that if in the same table (tbl_ComponentP arts) and same record a number in the field (ComponentID) and text in the field (Part) are the same in another record in that table then count those records. Example:
Expand|Select|Wrap|Line Numbers
  1. ComponentID             Part
  2.       1                test 2
  3.       36               test 13
  4.       1                test 2
  5.       1                test 1
The count would be 2 because two fields are the same.
Aug 23 '19 #1
6 1164
NeoPa
32,566 Recognized Expert Moderator MVP
GROUP BY the two Fields in question then Count(*).
Aug 23 '19 #2
soggycashew
10 New Member
Thanks NeoPA that works.... Now to use it in a VBA SQL how would my query SQL go?

Expand|Select|Wrap|Line Numbers
  1. SELECT tbl_ComponentParts.ComponentID, tbl_ComponentParts.Part, Count(*) AS UsedAlready
  2. FROM tbl_ComponentParts
  3. GROUP BY tbl_ComponentParts.ComponentID, tbl_ComponentParts.Part
  4. HAVING (((Count(*))>1));
  5.  
Aug 23 '19 #3
NeoPa
32,566 Recognized Expert Moderator MVP
I don't believe I understand the follow-on question.

Your SQL seems fine. No idea what VBA SQL could possibly refer to.
Aug 24 '19 #4
soggycashew
10 New Member
Im trying to figure out something what can be removed in the strSQL and how to do the same thing with a DCOUNT.

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL as integer
  2.  
  3. strSql = "SELECT tbl_ComponentParts.ComponentID, Count(*) AS UsedAlready " & vbCrLf & _
  4. "FROM tbl_ComponentParts " & vbCrLf & _
  5. "WHERE (((tbl_ComponentParts.ProductID)=[Forms]![frm_UpdateProductComponentsParts]![cboProduct])) " & vbCrLf & _
  6. "GROUP BY tbl_ComponentParts.ComponentID " & vbCrLf & _
  7. "HAVING (((Count(*))>1));"
  8.  
  9. If IsNull(strSQL) then 
  10. 'do this
  11. Else
  12. 'Do that
  13. end if
  14.  
Or convert the SQL into a DCount for a text box, how would that go?

Expand|Select|Wrap|Line Numbers
  1. =DCOUNT("*","tbl_ComponentParts","ProductID=" & [Forms]![frm_UpdateProductComponentsParts]![cboProduct] and something else?
Aug 24 '19 #5
twinnyfo
3,653 Recognized Expert Moderator Specialist
SoggyCashew,

I’m not sure I understand your question. I think you have your answer to the DCount() issue with your last bit of code. Just use all the criteria to need to count the specific records you are interested in. Since you are only using one table, that should be pretty straightforward .
Aug 24 '19 #6
NeoPa
32,566 Recognized Expert Moderator MVP
SoggyCashew:
Im trying to figure out something what can be removed in the strSQL and how to do the same thing with a DCOUNT.
I'm afraid that makes absolutely no sense to me. I can't even make it into a recognisable sentence.

I think you're possibly assuming I must understand based on an understanding of what you're thinking about that isn't actually correct. Unfortunately though, I can't help until you express the actual situation clearly.

Something that may prove helpful to know is that the Domain functions require a Domain parameter (Second) that is not SQL. QueryDefs or simple tables are fine and it will take the name of either as a valid string value.

Otherwise I can't help until I understand what you're asking for.
Aug 24 '19 #7

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

Similar topics

0
2653
by: DataFreakFromUtah | last post by:
Hello! No question here, just a procedure for the archive. Search critera: count records imported count data imported count number of rows imported count number of records imported record import count automatically import and count records prompt for number of records imported import count auto-import records autoimport records count records before and after
17
2063
by: Wilfried | last post by:
Hi, I have 5 tables: main data1
3
2151
by: shaqattack1992-newsgroups | last post by:
Hello Everyone, At work, employees have been using a spreadsheet that I am trying to import into an access database to make some reports. The problem I'm having is that in the spreadsheet, they are storing the same type of information in multiple cells. For example, for each machine in the shop, there is a code for why the machine was down--A1, B1, C1...for example. The spreadsheet is set up like this: ...
23
3401
nehashri
by: nehashri | last post by:
hi i am designing a database using Ms Access and ASP. i have 3 tables in access namely 'PERSONAL', other as 'POLICY' and 3rd one is named as 'STAFF'. in the contact table i have ID, Name, Children as fields. Also in policy table the firlds are:- ID, date_of_policy, no_policy, amount_paid, amount_balance and similarly the 3rd ie., staff has few fields. all three are linked my a common field which is ID all i want is when the user searches...
12
3524
by: Studiotyphoon | last post by:
Hi, I have report which I need to print 3 times, but would like to have the following headings Customer Copy - Print 1 Accounts Copy - Print 2 File Copy -Print 3 I created a macro to print the report three times, but do not know how
1
1430
by: Gareth Jones | last post by:
Hi all, I am attmepting to run a query based on 2 tables. In the query there are 3 fields from table 1 and 2 fields from table 2. The common field in both is Change.ID The query is working however there is about 70% of the data missing from the 2 fields in table 2
9
5055
by: Adam Adams | last post by:
Hai I need some help, for the record I am new to VB and access I have two tables (parent) and (child) . I want to count the number of children for each parent. I want to use date of birth and not ChildID. The number must be returned to table (parent) field amount This must be very simple
2
2111
by: achikeziey | last post by:
select mobile ,count(id) from (select mobile ,id from phone_1204 where astatus='newsub' and left(service,4)='euro' union all select mobile,id from phone_1205 where astatus='newsub' and left(service,4)='euro' ) group by mobile are this the right code
3
3469
by: DesignsOnline | last post by:
I have a table with many different fields in, including 40 separate image fields. ("Pic1" "Pic2" "Pic3" etc...) each field has a single value (an image name) in, I need to be able to select all these fields as a single record and loop through them. Something like Select Pic1, Pic2, Pic3, Pic4, etc... From Gallery Where GalleryID = 123 Each gallery has a unique id in the table and has several different fields including a couple of text...
1
954
by: isantiago926 | last post by:
I'd like to know ho I can compute a count of the same names or codes between different fields. For example, I have 4 fields each with different region names. I'd like to have a field counting all equal occurrences comparing all fields. If f1="X",f2="X",f3="X",f4="X" then CountField = 4
0
8127
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8567
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8527
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8215
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
6993
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5509
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4015
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2529
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
1
1658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.