Solved

Using Dcount for finding duplicates

Posted on 1998-06-22
6
834 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

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)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Omit After Update event 5 46
Balance After Payment 12 62
Conditional Format if Between Dates 9 45
SQL using aggregate function with HAVING / WHERE clause. 8 51
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

739 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