Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using Dcount for finding duplicates

Posted on 1998-06-22
6
Medium Priority
?
876 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

704 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