Solved

Using Dcount for finding duplicates

Posted on 1998-06-22
6
780 Views
Last Modified: 2012-06-22
How to use Dcount to find duplicates when the record has
multiple attributes in the primary key. I cannot get the
sample in ACC97 to work. Running this as a BeforeUpdate macro fails to update the DCount parameters when I add a new record.
0
Comment
Question by:lamalcz
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:spiridonov
Comment Utility
Pls, post the code that fails.
0
 
LVL 6

Accepted Solution

by:
devtha earned 120 total points
Comment Utility
This is what I do on a before update event of the field
[SocialSecurityNumber]. How ever this is to check if the entry is valid and matches to any existing valid SSN in the HRIS employee Table. The same can be done in your case.

SSN is the field name in HRIS table.
In your case you can use the same condition and let the user proceed if the count = 0 else cancel the event.
Devtha

If DCount("[SSN]", "HRIS", "[SSN] = FORMS![TRAINING DATA ENTRY]![SocialSecurityNumber]") = 0 Then
MsgBox "SSN NOT IN THE DATABASE"
SendKeys "{ESC}{ESC}{ESC}"
Cancel = True
End If

0
 

Author Comment

by:lamalcz
Comment Utility
Single attribute keys are easy, try this mixed variable case.
DCount("*","tblBank","DocumentID = '" & Forms!frmDEBank.cboDocumentID & "' And BankID = Forms!frmDEBank.BankID")>0
BankID is an integer, cboDocumentID is a combo box on a string.
As I enter new BankIDs and DocumentIDs the code the runs my "duplicate key" form but the form always shows the last Bank record, not the one I am currently entering! That is the Dcount keeps using the last record in the table and not the new record I am entering.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:lamalcz
Comment Utility
Adjusted points to 125
0
 
LVL 6

Expert Comment

by:devtha
Comment Utility
Instead of using dcount establish a recordset. I am posting theis from home I shall give you the correct syntax tomorrow morning.
But this is how it goes.

Dim dbs As Database, rst As Recordset,rcount as integer

' Modify this line to include the path to dbname on your computer.

      Set dbs = OpenDatabase("dbname.mdb")

Set rst = dbs.OpenRecordset("SELECT statement  ;")
' select statement is the query that will bring the recordcount you are looking for
      
      ' Populate the Recordset.
      rst.MoveLast
      
rcount = rst.recordcount
if rcount > 0 then
msgbox rcount
else...
end if          'You got the idea?


      dbs.Close




0
 
LVL 6

Expert Comment

by:devtha
Comment Utility
Ignore the posting from home comments.....
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now