We help IT Professionals succeed at work.

Duplicates Query

pdvsa
pdvsa asked
on
19 Views
Last Modified: 2020-05-21
Experts,

I have an issue with duplicate invoice numbers.
I have a form built on tblPayments and [InvoiceNo] is the field I enter the invoice number.

I built a duplicates query as follows:
SELECT tblPayments.InvoiceNo, tblPayments.Amount, tblPayments.PaymentDate, tblPayments.ExpectedPmtDate, tblPayments.NotPaid, tblPayments.DateSentHB
FROM tblPayments
WHERE (((tblPayments.InvoiceNo) In (SELECT [InvoiceNo] FROM [tblPayments] As Tmp GROUP BY [InvoiceNo] HAVING Count(*)>1 )))
ORDER BY tblPayments.InvoiceNo;

When I tab out of [InvoiceNo] the AfterUpdate event fires and the query appears but it shows all duplicates and I dont want to see them all.  I want filter on the the current record [tblPayments.InvoiceNo], which would be the record I am entering.  


Let me know if it is not clear.
thank you...
Comment
Watch Question

GozrehSoftware Developer
CERTIFIED EXPERT

Commented:
What code are you using to open this query?
You can use a form and filter the form with the InvoiceNo.

Also, Why are you not setting the invoiceNo field as unique (Indexed - No Duplicates), so it will not allow duplicates?


Daniel PineaultPresident / Owner CARDA Consultants Inc.
CERTIFIED EXPERT
Distinguished Expert 2018
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Dale FyeOwner, Dev-Soln LLC
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
pdvsaProject finance

Author

Commented:
Gozreh, I didnt think of adding an index for no duplicates but since there are duplicates I dont think I can do that now unless I delete the duplicates but I need to keep them.  Its odd I know.  

Daniel:  kindly see error:
pdvsaProject finance

Author

Commented:
Hi Dale,

You are right Dale. There could be >1 pmt per invoice.  Also, >1 credit too.  I dont have those cases but yes it will likely be the case at some pt. 
I however get a syntax error:
cursor goes to the ORDER line after I hit OK. 
SELECT tblPayments.InvoiceNo, tblPayments.Amount, tblPayments.PaymentDate, tblPayments.ExpectedPmtDate, tblPayments.NotPaid, tblPayments.DateSentHB
FROM tblPayments
WHERE (((tblPayments.InvoiceNo) In (SELECT InvoiceNo FROM tblPayments as Tmp WHERE InvoiceNo = [forms]![frmDupesInvNo].txtInvoiceNo GROUP BY InvoiceNo HAVING Count(*) > 1))
ORDER BY tblPayments.InvoiceNo;
pdvsaProject finance

Author

Commented:
Daniel, also not sure what Eval is and how its different than not having it in the code. 
Software Developer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
pdvsaProject finance

Author

Commented:
Very nice.  Works great.   Thank you so much. 

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.