PC Review


Reply
Thread Tools Rate Thread

Check for duplicates with multiple criteria

 
 
mbparks
Guest
Posts: n/a
 
      23rd May 2010
My table contains a field labled "Case Number" and another field labled "Date
Completed". I have created an input form and included code to check for
duplicate case numbers. A msgbox appears with a warning. I would like the
code to check for a duplicate case number and then check the "Date Completed"
field to see if it is blank. If it is blank I would like the existing
record to open. If the date completed field is not blank I would like to
continue entering data in the form to create a new record.
The code I am currently using is:

Private Sub Case_Number_BeforeUpdate(Cancel As Integer)
If DCount("*", "Copy of DIV 3 ICT Database", "[Case Number] = '" & Me![Case
Number] & "'") > 0 Then
MsgBox "This item already exists in the table."
Cancel = True
Me.Undo
End If
End Sub

How can I incorporate the changes?
Any help is greatly appreciated.

 
Reply With Quote
 
 
 
 
Arvin Meyer [MVP]
Guest
Posts: n/a
 
      23rd May 2010
You just need to check if Date Completed is blank before doing the Case
Number check:

Private Sub Case_Number_BeforeUpdate(Cancel As Integer)

If Len(Me.[Date Completed] & vbNullString) = 0 Then

Exit Sub

Else

If DCount("*", "Copy of DIV 3 ICT Database", _
"[Case Number] = '" & Me![Case Number] & "'") > 0 Then

MsgBox "This item already exists in the table."
Cancel = True
Me.Undo
End If

End If

End Sub

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access
Co-author: "Access 2010 Solutions", published by Wiley


"mbparks" <(E-Mail Removed)> wrote in message
news:2E16B3FA-A1E0-4682-A636-(E-Mail Removed)...
> My table contains a field labled "Case Number" and another field labled
> "Date
> Completed". I have created an input form and included code to check for
> duplicate case numbers. A msgbox appears with a warning. I would like
> the
> code to check for a duplicate case number and then check the "Date
> Completed"
> field to see if it is blank. If it is blank I would like the existing
> record to open. If the date completed field is not blank I would like to
> continue entering data in the form to create a new record.
> The code I am currently using is:
>
> Private Sub Case_Number_BeforeUpdate(Cancel As Integer)
> If DCount("*", "Copy of DIV 3 ICT Database", "[Case Number] = '" &
> Me![Case
> Number] & "'") > 0 Then
> MsgBox "This item already exists in the table."
> Cancel = True
> Me.Undo
> End If
> End Sub
>
> How can I incorporate the changes?
> Any help is greatly appreciated.
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter duplicates by multiple criteria Linda \(RQ\) Microsoft Excel New Users 1 10th Apr 2009 06:31 PM
Find duplicates in data with multiple criteria Danielle Microsoft Excel Misc 1 14th Dec 2007 03:56 PM
Query with multiple criteria returns duplicates meghanwh@gmail.com Microsoft Access Queries 7 13th Mar 2007 06:31 PM
How do I check for duplicates across multiple worksheets =?Utf-8?B?Q2hyaXNzeQ==?= Microsoft Excel Worksheet Functions 2 29th Jul 2006 06:34 PM
Find Duplicates (multiple criteria) Jeff F via AccessMonster.com Microsoft Access Queries 2 14th Nov 2005 09:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:52 PM.