Solved

Using Dcount for finding duplicates

Posted on 1998-06-22
6
791 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
ID: 1975667
Pls, post the code that fails.
0
 
LVL 6

Accepted Solution

by:
devtha earned 120 total points
ID: 1975668
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
ID: 1975669
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:lamalcz
ID: 1975670
Adjusted points to 125
0
 
LVL 6

Expert Comment

by:devtha
ID: 1975671
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
ID: 1975672
Ignore the posting from home comments.....
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

895 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

13 Experts available now in Live!

Get 1:1 Help Now