Limiting number of duplicate records

M

Michael

I'm trying to use If and DCount in my form to give me a message when a user
tries to create more than the allowed number of duplicate records. The number
of duplicates allowed is established in the table tblFloorProgCriteria.

These are the three fields where I’m looking for duplicates:

AuditID (Number Field)
FloorProgCriteriaID (Number Field)
AuditorID (Text Field)

Here’s what I have so far...

Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblFloorProgAudit", "[AuditID] = " & Me.[AuditID] & _
" and [FloorProgCriteriaID] = " & Me.[FloorProgCriteriaID] & _
"' and [AuditorID] = '" & Me.[AuditorID] & "'") > ????(Help)???? Then
MsgBox "You cannot enter more than 5 observations for these
criteria. Delete 1 of the
observations."
Cancel = True
End If
End Sub

Thanks in advance for your help!
 
M

Marshall Barton

Michael said:
I'm trying to use If and DCount in my form to give me a message when a user
tries to create more than the allowed number of duplicate records. The number
of duplicates allowed is established in the table tblFloorProgCriteria.

These are the three fields where I’m looking for duplicates:

AuditID (Number Field)
FloorProgCriteriaID (Number Field)
AuditorID (Text Field)

Here’s what I have so far...

Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("*", "tblFloorProgAudit", "[AuditID] = " & Me.[AuditID] & _
" and [FloorProgCriteriaID] = " & Me.[FloorProgCriteriaID] & _
"' and [AuditorID] = '" & Me.[AuditorID] & "'") > ????(Help)???? Then
MsgBox "You cannot enter more than 5 observations for these
criteria. Delete 1 of the
observations."
Cancel = True
End If
End Sub


There's an extra ' in "' and [AuditorID] = ...

It seems like you may need to use a DLookup to get the
number of duplicates allowed. Rather than make the DCount
too complicated to read, I suggest doing it in a separate
statement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top